user192362127
user192362127

Reputation: 11635

what is the return value of event.wait() function in python

Suppose i have this code

def wait_for_event(e):
    """Wait for the event to be set before doing anything"""
    logging.debug('wait_for_event starting')
    event_is_set = e.wait()
    logging.debug('event set: %s', event_is_set)

What is the value returned by e.wait()

i don't get it

One thing which is also not cleared to me is that how events send to threads.

Suppose i have threads which downlaods webpages which has name of manager on every page.

Now that name was edited my someone.

Now my thread 10 first got that chnage and now i want to send notification with that new name to all my threads , so that they can change that in their code

how can i do that

Upvotes: 1

Views: 4560

Answers (2)

NPE
NPE

Reputation: 500317

Since there's no timeout given to e.wait(), the method always returns True. This is spelled out in the documentation:

wait([timeout])

Block until the internal flag is true. If the internal flag is true on entry, return immediately. Otherwise, block until another thread calls set() to set the flag to true, or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof).

This method returns the internal flag on exit, so it will always return True except if a timeout is given and the operation times out.

Upvotes: 2

Pavel Anossov
Pavel Anossov

Reputation: 62908

wait([timeout])

Block until the internal flag is true. If the internal flag is true on entry, return immediately. Otherwise, block until another thread calls set() to set the flag to true, or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof).

This method returns the internal flag on exit, so it will always return True except if a timeout is given and the operation times out.

Changed in version 2.7: Previously, the method always returned None.

Upvotes: 0

Related Questions