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

Spawn worker threads with daemon=True on asyncio #321

Closed
wants to merge 1 commit into from

Conversation

davidbrochart
Copy link
Contributor

This was added in 635e25a:

thread = Thread(target=thread_worker, daemon=True)

And removed in #227:
thread = Thread(target=_thread_pool_worker, args=args, name='AnyIO worker thread')

Fixes jupyterlab/jupyterlab#10442

@graingert
Copy link
Collaborator

graingert commented Jun 23, 2021

daemon=True isn't well supported with subinterpreters and skips cleanup. Perhaps this is something that trio should support too: trio.to_thread.run_sync(fn, daemon=True|False)

@agronholm
Copy link
Owner

I removed daemon=True once I learned the above. Why does JupyterLab hang on server shutdown? Does it not clean up the tasks it creates?

@agronholm
Copy link
Owner

There is also the matter of issue #323 which I just fixed (and which will require a prompt bugfix release). Could it be related?

@graingert
Copy link
Collaborator

python-trio/trio#2046

@davidbrochart
Copy link
Contributor Author

There is also the matter of issue #323 which I just fixed (and which will require a prompt bugfix release). Could it be related?

It doesn't seem to be related, 49f666e doesn't fix the JupyterLab hang.

Why does JupyterLab hang on server shutdown? Does it not clean up the tasks it creates?

The issue is actually in Jupyter Server, which uses Tornado. Shutting down simply stops Tornado's event loop, and waits for each task to finish. But I think it is because of a task in a worker thread which is not thread-safe. I opened jupyter-server/jupyter_server#545 which should fix the issue.

I thought daemon=True was removed by mistake, but anyway this doesn't seem to be the root cause of our issue, so it is fine to close this PR. Thanks for your help!

@agronholm agronholm closed this Jun 24, 2021
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

Successfully merging this pull request may close these issues.

JupyterLab hangs on server shut down
3 participants