You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: Can't run subprocess.Popen(..., stdout=sys.stdout) in IPython window #272
Yes, the stdout and err are not files in the ipykernel as they are hooked to ZMQ.
You can use the ! who syntax or %sc, %sx magics to do this kind of things when using ipykernel.
You would need to use a pipe, pull data from it and write it to stdout yourself. This should work both in ipykernel and in a terminal. I wrote a little example of doing that here:
It gets trickier if you need to get stderr separately, or supply stdin at the same time, because then you need to avoid deadlocks (your code waiting to read/write one pipe while the subprocess is waiting to write/read a different one). But if you just want to display output live, it's quite easy.
(If the program will run briefly and it's OK to show output when it's finished, it's even easier:
Activity
Carreau commentedon Oct 24, 2017
Yes, the stdout and err are not files in the ipykernel as they are hooked to ZMQ.
You can use the
! whosyntax or%sc,%sxmagics to do this kind of things when using ipykernel.larsoner commentedon Oct 24, 2017
Unfortunately that workaround does not allow code to be written to work in both
ipykerneland regular Python / IPython.takluyver commentedon Oct 25, 2017
You would need to use a pipe, pull data from it and write it to stdout yourself. This should work both in ipykernel and in a terminal. I wrote a little example of doing that here:
https://github.com/takluyver/rt2-workshop-jupyter/blob/e7fde6565e28adf31a0f9003094db70c3766bd6d/Subprocess%20output.ipynb
It gets trickier if you need to get
stderrseparately, or supplystdinat the same time, because then you need to avoid deadlocks (your code waiting to read/write one pipe while the subprocess is waiting to write/read a different one). But if you just want to display output live, it's quite easy.(If the program will run briefly and it's OK to show output when it's finished, it's even easier:
)
takluyver commentedon Oct 25, 2017
Alternatively, Min's wurlitzer package might be able to help you.
larsoner commentedon Oct 26, 2017
Okay, I'll see if I can work around the issue for now. Thanks for the tips