Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup file descriptors watcher thread #1283

Open
dfalbel opened this issue Oct 23, 2024 · 0 comments
Open

Cleanup file descriptors watcher thread #1283

dfalbel opened this issue Oct 23, 2024 · 0 comments

Comments

@dfalbel
Copy link

dfalbel commented Oct 23, 2024

It seems that IOStreams are not correcly calling their close method as in:

def close(self):
"""Close the stream."""
if self._should_watch:
self._should_watch = False
# thread won't wake unless there's something to read
# writing something after _should_watch will not be echoed
os.write(self._original_stdstream_fd, b"\0")
if self.watch_fd_thread is not None:
self.watch_fd_thread.join()
# restore original FDs
os.dup2(self._original_stdstream_copy, self._original_stdstream_fd)
os.close(self._original_stdstream_copy)
if self._exc:
etype, value, tb = self._exc
traceback.print_exception(etype, value, tb)
if self._has_thread:
self.pub_thread.stop()
self.pub_thread = None

Thus, even though reset_io is called when closing the IPKernelApp:

def reset_io(self):
"""restore original io
restores state after init_io
"""
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
sys.displayhook = sys.__displayhook__

sys.stdout is still not functioning as expected after IPyKernelApp closes, because the writes are being redirected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant