[Python-ideas] Simpler thread synchronization using "Sticky Condition"

Antoine Pitrou solipsis at pitrou.net
Tue Mar 26 06:38:14 EDT 2019


On Tue, 26 Mar 2019 09:27:18 -0000
"Richard Whitehead" <richard.whitehead at ieee.org>
wrote:
> Problem: 
> 
> Using Python's Condition class is error-prone and difficult. For example,
> the following pseudo-code would be quite typical of its use:
[...]

Nowadays, I would recommend to always use `Condition.wait_for()` rather
than `Condition.wait()`.

A Condition, unlike what the name suggests, is just a means of
synchronization.  It doesn't have a boolean state per se.  You have to
manage your boolean state (or any other kind of state) separately, hence
the usefulness of `wait_for()`.

As for auto-reset events, the Windows API has them, here's an
insightful writeup about them:
https://devblogs.microsoft.com/oldnewthing/?p=30773

But, yes, perhaps auto-reset events would be a good addition
regardless.  Either through a flag to Event, or as a separate class.

Regards

Antoine.




More information about the Python-ideas mailing list