Open jhidding opened 4 years ago
I found out what triggers the error: stdout was closed when the kernel tried to start. I'll rename the issue.
Example to trigger:
#!/usr/bin/env python
import jupyter_client
import sys
def main():
sys.stdout.close()
with jupyter_client.run_kernel(kernel_name="python3") as kc:
print(kc.is_alive(), file=sys.stderr)
if __name__ == "__main__":
main()
I am having the same issue with standard input closed. Here is an example that throws the same ValueError
as above:
import sys
from jupyter_client.manager import start_new_kernel
sys.stdin.close()
start_new_kernel()
This issue appears to stem from IPython. This code runs when we call start_new_kernel
, which calls isatty()
on stdin, stdout, and stderr. Calling isatty()
on a closed stdin throws the same ValueError
:
import sys
sys.stdin.close()
sys.stdin.isatty()
I wish isatty()
would return False
if the stream is closed. It does not, and so I think IPython should only call isatty()
if the stream is open. We should probably file an issue on that repository.
Until this is resolved, I have a workaround:
setattr(sys.stdin, "isatty", lambda: False)
@jhidding, I (hopefully!) solved this issue with ipython/ipython#13701. The fix should be released in an upcoming version of IPython.
Not sure if this is an issue with
jupyter_client
orpanflute
. Taking this minimal example (call it test-jupyter.py):And running it with
(press Ctrl-D to end input) Gives the following error:
Just running
finalize(None)
and calling that outside thepanflute
framework works fine. Somehow the magic insidetraitlets
is affected bypanflute
, but I can't fathom how.Any help is much appreciated. Regards, Johan