Comment 0 for bug 1770302

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

mwhudson@ringil:~/src/ssh-import-id$ ssh-import-id gh:mwhudso
Username "mwhudso" not found at GitHub API
mwhudson@ringil:~/src/ssh-import-id$ ssh-import-id gh:mwhudso | cat
mwhudson@ringil:~/src/ssh-import-id$

What happened? The offending code looks like

  if resp.status_code == 404:
   print('Username "%s" not found at GitHub API' % ghid)
   os._exit(1)

print does not flush by default. When stdout is a terminal you get an implicit flush on newline but when it's a pipe you do not and calling _exit(1) exits the process without flushing the buffers either. Two fixes suggest themselves: 1) add flush=True to the print() calls 2) exiting more conventionally by e.g. calling sys.exit()