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

Experiment with threadpools #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SylvainCorlay
Copy link
Member

@SylvainCorlay SylvainCorlay commented Sep 23, 2020

I am seeing many issues with nest-asyncio. Trying out threadpools.

check_patch_tornado()
return loop.run_until_complete(coro)

return pool.submit(asyncio.run, coro).result()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have only this line in the function, so that we always run in a thread with its own event loop.

@@ -28,6 +30,7 @@ def check_patch_tornado() -> None:
tornado.concurrent.FUTURES = \
tornado.concurrent.FUTURES + (asyncio.Future, ) # type: ignore

pool = concurrent.futures.ThreadPoolExecutor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to use more than one thread? I think we should use max_workers=1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_worker should be fine IMO.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't specify mar_workers, it will use unnecessary resources: "If max_workers is None or not given, it will default to the number of processors on the machine, multiplied by 5".
Since you never actually run concurrently, you don't need more than 1 thread.

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.

2 participants