Fabio Manganiello <i...@fabiomanganiello.com> added the comment:

+1

I have similar applications (both using multithreading and multiprocessing) 
which rely upon waiting for events to be both set and unset. Some example 
common pattern:

```
from multithreading import Thread, Event, Queue
import time

q = Queue()
reading = Event()

def read_from_device(device):
    # Wait for the caller to signal that it's ready to receive
    reading.wait()
    data = get_data(device)

    while data:
        data = get_data(device)
        q.put(data)

    # Once we're done receiving data, wait for the caller to
    # signal that it has received everything
    while reading.is_set():
        time.sleep(1)

    # Do some other operations once all threads are in sync
    release_device(device)

processor = threading.Thread(target=read_from_device, args=(device,))
processor.start()

# Do something else

reading.set()

# Get data from the processor
data = q.get()
while data:
    preprocess_data(data)
    data = q.get()

# Do something before we're ready to clean up everything
process_data()

# Signal to the processor that we're done
reading.clear()
```

Events (and I'd say that this also applies to Conditions) are supposed to be 
symmetric - one can either wait for an event to be set or cleared - but the 
implementation provided by the current API is definitely asymmetric - `wait()` 
can be used to wait for an event to be set, but if you want to wait for it to 
be cleared then the only provided approach is through a poll on `is_set()`.

----------
nosy: +BlackLight

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40871>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to