-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add main_thread_only execmodel #243
Add main_thread_only execmodel #243
Conversation
How does this behave when multiple tasks are being sent At first glance it seems like it could break usages |
I ran the tests localy and it seems to somehow deadlock in this one: It hangs on I wonder if there's some way to handle it without a deadlock... I suppose there's probably some queue.Queue usage that could work here. |
That test is a small approximate of the case I mentioned Basically if the main thread is busy and you send in a task, the wait will break the gateway |
This comment was marked as resolved.
This comment was marked as resolved.
Nope, that just hides the issue somewhere that's hard to control My rough plan was to completely drop exec models to provide async support for execnet via asyncio/trio/curio |
Can you help me understand what makes it hard to control? Rather than launch a Thread in _local_schedulexec, I would prefer to use a queue.Queue instance to queue an asynchronous call to
That seems like an entirely reasonable thing to do (I noticed #150). However, guaranteed scheduling in the main thread as required to solve pytest-dev/pytest-xdist#620 seems like it might be doable given that in my experience the "thread" execmodel nearly provides this guarantee as it is, but maybe I'm being naive due to my lack of familiarity with execnet in general. |
@zmedico the key issue here is that it is absolutely valid to run multiple tasks concurrent - so waiting for it to be finished is techically wrong, which is why the test for the rinfo busy fails unless there is a mechanism to give tagged expectations (for main thread tasks) its unlikel to have it correct |
Thanks for the explanation. So, I suppose the plan would be to add support to tag the expectation when we drop execmodel support.
In the interim for the elimination of execmodel, I suppose we could add a |
introducing a main_thread_only model could be a good starting point |
be707da
to
4f69add
Compare
6e24bbf
to
4f86b2a
Compare
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been proposed in pytest-dev/execnet#243, so this patch should not be merged until there is a release version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
@RonnyPfannschmidt This main_thread_only implementation seems to work pretty well for me in combination with a pytest-xdist patch that I've created to utilize it. I tend to see a lot of pytest-xdist worker crashes like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we find a way to incorporate a timeout or a quick error, the name should indicate its a hack
I'd recommend to add a timeout and erroring when the task can't be started within a reasonable timeframe
There should be a test that validates this error happens after a reasonable timeout
This comment was marked as resolved.
This comment was marked as resolved.
4f86b2a
to
53332fd
Compare
180d3ea
to
e6071f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zmedico!
Left some minor suggestions to the CHANGELOG. 👍
464a0ed
to
db8317a
Compare
d72144c
to
db8317a
Compare
db8317a
to
c5cef44
Compare
Thanks @zmedico! @RonnyPfannschmidt would you like to do the honors of merging/releasing this one? 😁 |
Absolutely, I'll get to it later today This one is a big plus as it does resolve a issue with xdist paining us ever since exec models where added |
…task_in_try_send_to_primary_thread
thanks again ! |
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been proposed in pytest-dev/execnet#243, so this patch should not be merged until there is a release version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been proposed in pytest-dev/execnet#243, so this patch should not be merged until there is a release version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been proposed in pytest-dev/execnet#243, so this patch should not be merged until there is a release version of execnet supporting the main_thread_only execmodel. Also increase minimum python version to 3.8 since execnet dropped 3.7 support in pytest-dev/execnet#245.
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been proposed in pytest-dev/execnet#243, so this patch should not be merged until there is a release version of execnet supporting the main_thread_only execmodel. Also increase minimum python version to 3.8 since execnet dropped 3.7 support in execnet#245.
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Also increase minimum python version to 3.8 since execnet dropped 3.7 support in pytest-dev/execnet#245. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Also increase minimum python version to 3.8 since execnet dropped 3.7 support in pytest-dev/execnet#245. Closes: pytest-dev#620
Corresponding pytest-xdist MR submitted as pytest-dev/pytest-xdist#1027. |
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Closes: pytest-dev#620
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Closes #620
This is a possible regression cause: xref pytest-dev/pytest-xdist#1070 (comment) |
In order to prevent tasks from running in a non-main thread, wait for the previous task inside _try_send_to_primary_thread, then schedule the next task. Add a main_thread_only execmodel to distinguish this new behavior from the existing thread execmodel, since users of the thread execmodel expect that tasks can run in multiple threads concurrently. If concurrent remote_exec requests are submitted for the main_thread_only execmodel, then the channel will raise a RemoteError with this message:
In order for main_thread_only users to avoid this error, remote_exec callers must use the returned channel to wait for a task to complete before they call remote_exec again, as demonstrated in test_assert_main_thread_only. Testing of main_thread_only with pytest-xdist has shown that this behavior is compatible with the existing pytest-xdist usage because it never calls remote_exec more than once per gateway.
Closes: #96