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

trio.Event.clear() is deprecated #61

Closed
mehaase opened this issue Sep 5, 2019 · 3 comments
Closed

trio.Event.clear() is deprecated #61

mehaase opened this issue Sep 5, 2019 · 3 comments

Comments

@mehaase
Copy link

mehaase commented Sep 5, 2019

I am getting a deprecation warning:

.../python3.7/site-packages/trio_asyncio/base.py:718: TrioDeprecationWarning: trio.Event.clear is deprecated since Trio 0.12.0; use multiple Event objects or other synchronization primitives instead (python-trio/trio#637)

The deprecation references python-trio/trio#637 for more information. In short, Event.clear() is a foot gun that is prone to creating race conditions. The general recommendation is to create new events instead of clearing existing ones. It's not clear to me whether this recommendation would work in this circumstance:

self._stopped.clear()

The event is set as soon as its created, then cleared when control enter the asyncio main loop. This is an unsual way to use trio.Event, which makes me hesitant to say whether this is an easy to fix or not...

I also haven't checked if there are other uses of Event.clear() in the code.

@parity3
Copy link

parity3 commented Dec 16, 2019

I'm getting this too. As a hack to remove the deprecation warning messages for the time being, I think it's pretty safe to put in the following code:

def clear_event(self):
    assert not self._stopped.statisticts().tasks_waiting, "unable to clear event due to other waiters"
    self._stopped = trio.Event()

At least then it will fail in an explicit way. I'm not planning on running more than 1 loop for the process lifetime of my app so I'm probably safe here.

@pquentin
Copy link
Member

pquentin commented Mar 1, 2020

This also affects the pytest-trio tests: python-trio/pytest-trio#91

@pquentin
Copy link
Member

pquentin commented Mar 9, 2020

Fixed in #66, 0.11.0 should be released soon.

@pquentin pquentin closed this as completed Mar 9, 2020
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

3 participants