Bases: object
an event for which greenlets can wait
mirrors the standard library threading.Event API
clear the event from being triggered
after calling this method, waiting on this event will block until the set() method has been called
indicates whether waiting on the event will block right now
Returns: | True if the event has been set() and waiting will not block, False if the event is cleared and wait() will block |
---|
indicates whether waiting on the event will block right now
Returns: | True if the event has been set() and waiting will not block, False if the event is cleared and wait() will block |
---|
set the event to triggered
after calling this method, all greenlets waiting on the event will be rescheduled, and calling wait() will not block until clear() has been called
pause the current coroutine until this event is set
Note
this method will block the current coroutine if set() has not been called.
Parameters: | timeout (number or None) – the maximum amount of time to block in seconds. the default of None allows indefinite blocking. |
---|---|
Returns: | True if a timeout was provided and was hit, otherwise False |
Bases: object
an object that can only be ‘owned’ by one greenlet at a time
mirrors the standard library threading.Lock API
lock the lock, blocking until it becomes available
Note
this method will block the current coroutine if the lock is not already owned.
Parameters: | blocking (bool) – whether to block if the lock is already owned (default True) |
---|---|
Returns: | a bool indicating whether the lock was acquired. In the default case of blocking = True this will always be the case, but may not be otherwise. |
lock the lock, blocking until it becomes available
Note
this method will block the current coroutine if the lock is not already owned.
Parameters: | blocking (bool) – whether to block if the lock is already owned (default True) |
---|---|
Returns: | a bool indicating whether the lock was acquired. In the default case of blocking = True this will always be the case, but may not be otherwise. |
indicates whether the lock is currently locked
Returns: | True if the lock is locked (and therefore calling acquire() would block), otherwise False |
---|
indicates whether the lock is currently locked
Returns: | True if the lock is locked (and therefore calling acquire() would block), otherwise False |
---|
Bases: greenhouse.util.Lock
a lock which may be acquired more than once by the same greenlet
mirrors the standard library threading.RLock API
acquire ownership of the lock
if the lock is already owned by the calling greenlet, a counter simply gets incremented. if it is owned by a different greenlet then it will block until the lock becomes available.
Note
this method will block the current coroutine if the lock is not already owned by another coroutine.
Parameters: | blocking (bool) – whether to block if the lock is owned by a different greenlet (default True) |
---|---|
Returns: | a bool indicating whether the lock was acquired. In the default case of blocking = True this will always be the case, but may not be otherwise. |
Bases: object
a synchronization object capable of waking all or one of its waiters
mirrors the standard library threading.Condition API
Parameters: | lock (Lock or RLock) – the lock object wrapped by the condition |
---|
wake one or more waiting greenlets
Parameters: | num (int) – the number of waiters to wake (default 1) |
---|---|
Raises : | RuntimeError if the underlying lock hasn’t been acquired |
wake all waiting greenlets
Raises : | RuntimeError if the underlying lock hasn’t been acquired |
---|
Bases: object
a synchronization object with a counter that blocks when it reaches 0
mirrors the api of threading.Semaphore
Parameters: | value (int) – the starting value of the counter |
---|
decrement the counter, waiting if it is already at 0
Note
if the counter is already at 0, this method will block the current coroutine until a release() increments it again.
Parameters: | blocking (bool) – whether or not to block if the counter is already at 0 (default True) |
---|---|
Returns: | a bool, indicating whether the count was decremented (this can only be False if blocking was False – otherwise it would have blocked until it could decrement the counter) |
increment the counter, waking up a waiter if there was any
Bases: greenhouse.util.Semaphore
a semaphore with an upper limit to the counter
mirrors the api of threading.BoundedSemaphore
Parameters: | value (int) – the starting and maximum value of the counter |
---|
increment the counter, waking up a waiter if there was any
Bases: greenhouse.util.Thread
creates a greenlet from a function and schedules it to run later
mirrors the standard library threading.Timer API
Parameters: |
|
---|
attempt to prevent the timer from ever running its function
Returns: | True if it was successful, False if the timer had already run or been cancelled |
---|
a classmethod decorator to immediately turn a function into a timer
Note
you won’t find this on threading.Timer, it is an extension to that API
this is a function returning a decorator, so it is used like so:
>>> @Timer.wrap(5, args=("world",))
>>> def say_hi_timer(name):
... print "hello, %s" % name
Parameters: |
|
---|---|
Returns: | a decorator function which produces an unstarted Timer |
Bases: object
an object that holds greenlet-local data
mirrors the standard library threading.local API
to use, simply create an instance with no arguments, and any attribute gets and sets will be specific to that greenlet
Bases: object
a standin class for threads, but powered by greenlets
this class is useful for monkey-patching the standard library, but for code written explicitly for greenhouse, the functions in greenhouse.scheduler are a better way to go
mirrors the standard library threading.Thread API
Parameters: |
|
---|
whether the thread is set as a daemon thread (unsupported)
the thread’s name as passed in the constructor or set_name(), or failing those the automatically generated name
Returns: | the thread’s str name |
---|
the thread’s name as passed in the constructor or set_name(), or failing those the automatically generated name
Returns: | the thread’s str name |
---|
unique identifier for this thread
indicates whether the thread is currently running
Returns: | True if start() has already been called but the function hasn’t yet finished or been killed, False if it isn’t currently running for any reason. |
---|
whether the thread is in daemonized mode
Returns: | True. this is here for compatibility with threading.Thread, greenhouse-based threads always operate like daemonized threads. |
---|
indicates whether the thread is currently running
Returns: | True if start() has already been called but the function hasn’t yet finished or been killed, False if it isn’t currently running for any reason. |
---|
whether the thread is in daemonized mode
Returns: | True. this is here for compatibility with threading.Thread, greenhouse-based threads always operate like daemonized threads. |
---|
block until this thread terminates
Note
this method can block the calling coroutine if the thread has not yet completed.
Parameters: | timeout (int, float or None) – the maximum time to wait. with the default of None, waits indefinitely |
---|---|
Raises : | RuntimeError if called inside the thread, or it has not yet been started |
override this method to define the thread’s behavior
this is an alternative way to define the thread’s function than passing target to the constructor
here for compatibility with threading.Thread (this doesn’t work).
Parameters: | daemonic (bool) – whether attempting to turn daemon mode on or off |
---|
overwrite the thread’s name
Parameters: | name (str) – the name to set |
---|
here for compatibility with threading.Thread (this doesn’t work).
Parameters: | daemonic (bool) – whether attempting to turn daemon mode on or off |
---|
overwrite the thread’s name
Parameters: | name (str) – the name to set |
---|
schedule to start the greenlet that runs this thread’s function
Raises : | RuntimeError if the thread has already been started |
---|
Bases: object
a producer-consumer queue
Parameters: | maxsize (int) – optional limit to the amount of queued data, after which put() can block. the default of 0 turns off the limit, so put() will never block |
---|
mirrors the standard library Queue.Queue API
indicate whether there is any queued data
Returns: | True if there is data in the queue, otherwise False |
---|
indicate whether the queue has maxsize data queued
Returns: | True if the queue’s data has reached maxsize, otherwise False |
---|
get an item out of the queue
Note
if block is True (the default) and the queue is :meth`empty`, this method will block the current coroutine until something has been put().
Parameters: |
|
---|---|
Raises : | Empty if there is no data in the queue and block is False, or timeout expires |
Returns: | something that was previously put() in the queue |
get an item out of the queue without ever blocking
this call is equivalent to get(block=False)
Returns: | something that was previously put() in the queue |
---|
wait for task completions
Note
if task_done() has not been called for every put() call, this method will block until it has.
the queue is still usable after a join() call. a return from join() simply indicates that the queue has no jobs currently pending.
Parameters: | timeout (int, float or None) – the maximum amount of time to wait in seconds. the default of None allows indefinite waiting. |
---|---|
Returns: | True if timeout was provided and expired, otherwise False |
put an item into the queue
Note
if the queue was created with a maxsize and it is currently full(), this method will block the calling coroutine until another coroutine get()s an item.
Parameters: |
|
---|---|
Raises : | Full if the queue is full() and block is False, or if timeout expires. |
put an item into the queue without any chance of blocking
this call is equivalent to put(block=False)
;param item: the object to put into the queue, can be any type
the number of queued pieces of data
Returns: | int |
---|
mark that a “job” (corresponding to a put() or put_nowait() call) is finished
the join() method won’t complete until the number of task_done() calls equals the number of put() calls
Bases: greenhouse.util.Queue
a producer-consumer queue that produces items in LIFO order
Parameters: | maxsize (int) – optional limit to the amount of queued data, after which put() can block. the default of 0 turns off the limit, so put() will never block |
---|
mirrors the standard library Queue.LifoQueue API
Bases: greenhouse.util.Queue
a producer-consumer queue that produces items in prioritized order
Parameters: | maxsize (int) – optional limit to the amount of queued data, after which put() can block. the default of 0 turns off the limit, so put() will never block |
---|
mirrors the standard library Queue.PriorityQueue API
Bases: object
a counter object that can block
the current integer value of the counter
decrement the counter and wake anyone waiting for the new value
increment the counter, and wake anyone waiting for the new value
wait until the count has reached a particular number
Note
this method can block the current greenlet
Parameters: | until (int) – the number to wait for the count to get down (or up) to. default 0 |
---|