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

Error prone pattern with background tasks that we wait till they are started. #106

Open
pipermerriam opened this issue May 29, 2019 · 0 comments

Comments

@pipermerriam
Copy link
Member

What was wrong?

We have a growing amount of code like this:

self._receiving_loop_running = asyncio.Event()
self._receiving_queue = asyncio.Queue()
self._running = True
self._endpoint_tasks.add(asyncio.ensure_future(self._connect_receiving_queue()))
await self._receiving_loop_running.wait()

  • an asyncio.Event to signal something that starts asynchronously in-fact running.
  • a coroutine that needs to be run in the background which will set the event once it has started.
  • a statement that waits for the event to be set..

This code is error prone.

  • easy to forget to wait for the event.
  • easy to forget to remove the event if the function gets refactored such that it isn't needed anymore.

How can it be fixed?

Not sure yet.

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