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

flush control queue prior to handling shell messages #658

Merged
merged 3 commits into from May 7, 2021

Conversation

minrk
Copy link
Member

@minrk minrk commented May 7, 2021

preserves control channel priority over shell channel

Always flush the control queue before processing shell messages. When control thread wasn't running, shell messages would often get handled before control messages that had arrived before they started processing, due to how the queues are flushed from zmq to processing queues and the removal of synchronization in #585.

This adds a flush immediately before any shell message is handled, which does:

  • control_stream.flush() pops messages from zmq to control_queue
  • float a threadsafe Future on control_queue to allow waiting for any pending messages to process (I first tried control_queue.qsize(), but that doesn't work because it goes to 0 when control starts processing the last request, not when it finishes)

This is much less of an issue when the control thread is running because control messages are usually quick, so the control queue is usually empty. So we could do this only when control thread is not running. However, that's not necessarily a safe assumption, and the behavior is now more correct in both cases, though it was usually fine with control_thread and always wrong without it.

with this, all ipyparallel tests are passing for me (#635)

minrk added 2 commits May 7, 2021 12:04
preserves control channel priority over shell channel

- when control thread is running, resolves message-processing races
- when control thread is not running, ensures control messages are processed before shell requests
@minrk minrk requested a review from SylvainCorlay May 7, 2021 10:10
@blink1073 blink1073 added this to the 6.0 milestone May 7, 2021
awaitable_future = asyncio.wrap_future(tracer_future)
else:
control_loop = self.io_loop
tracer_future = awaitable_future = asyncio.Future()
Copy link
Member

Choose a reason for hiding this comment

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

Nice way to make the flush awaitable across threads. I learned something.

@SylvainCorlay
Copy link
Member

This looks good to me!

@SylvainCorlay SylvainCorlay merged commit 7b4171c into ipython:master May 7, 2021
@minrk minrk deleted the flush-control-thread branch May 7, 2021 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants