Title: Theory / Important / CS / Programming / Python / Lib / threading
Tags: seen_description automatedNewLineAfterCommaSpace constant
On every note of this deck, unless a note says otherwise:
Language: Python
Page: https://docs.python.org/3/library/threading.html

Instruction: active_count()
Page: https://docs.python.org/3/library/threading.html
Effect: number of Thread objects currently alive
Library: threading

Instruction: current_thread()
Page: https://docs.python.org/3/library/threading.html
Returns: current Thread object, corresponding to the caller’s thread of control
Library: threading

Instruction: get_ident()
Page: https://docs.python.org/3/library/threading.html
Effect: ‘thread identifier’ of the current thread
Typ: non zero int
Library: threading

Instruction: enumerate()
Page: https://docs.python.org/3/library/threading.html
Effect: list of all Thread objects currently alive.
Extra: The list includes daemonic threads, dummy thread objects created by current_thread(), and the main thread. It excludes terminated threads and threads that have not yet been started.
Library: threading

Instruction: main_thread()
Page: https://docs.python.org/3/library/threading.html
Effect: main Thread object
Library: threading

Instruction: settrace(func)
Page: https://docs.python.org/3/library/threading.html
Returns: Set a trace function for all threads started from the threading module. The func will be passed to sys.settrace() for each thread, before its run() method is called.
Library: threading

Instruction: setprofile(func)
Page: https://docs.python.org/3/library/threading.html
Effect: Set a profile function for all threads started from the threading module. The func will be passed to sys.setprofile() for each thread, before its run() method is called.
Library: threading

Instruction: stack_size()
Page: https://docs.python.org/3/library/threading.html
Returns: The size of stack used to create thread
Library: threading

Instruction: stack_size(0)
Page: https://docs.python.org/3/library/threading.html
Effect: Next thread created will have default size of the system
Library: threading

Instruction: stack_size(size)
Page: https://docs.python.org/3/library/threading.html
Effect: Next thread created will have size size
Assuming: size at least 32 kb
Library: threading

Constant: TIMEOUT_MAX
Meaning: The maximum value allowed for the timeout parameter of blocking functions
Page: https://docs.python.org/3/library/threading.html
Language: Python

Typ: local
Meaning: variables locals to a thread
Language: Python
Library: threading

Typ: Thread
Meaning: an activity that is run in a separate thread of control
Language: Python
Library: threading

Instruction: t.start()
Page: https://docs.python.org/3/library/threading.html
Effect: Start a new thread, running the activity of t
Variables: t a thread
Library: threading

Question: How to create a subclass of Thread
Answer: Only by overriding __init__ and run
Page: https://docs.python.org/3/library/threading.html

Name: A thread alive
Definition: A thread started, whose run has not yet ended (neither by return, nor uncaught exception)
Page: https://docs.python.org/3/library/threading.html

Instruction: t.is_alive()
Page: https://docs.python.org/3/library/threading.html
Returns: Whether t is still alive ?
Variables: t a thread

Instruction: t.join()
Page: https://docs.python.org/3/library/threading.html
Returns: Wait until t ends
Variables: t a thread

Instruction: t.name
Page: https://docs.python.org/3/library/threading.html
Returns: Name of the thread t
Variables: t a thread

Name: A daemon thread
Definition: A thread which, by itself, does not justify to keep the program running
Page: https://docs.python.org/3/library/threading.html

Name: The main thread
Definition: The initial thread, started with python
Page: https://docs.python.org/3/library/threading.html
Context: Python

Name: Dummy thread object
Definition: threads of control started outside the threading module, such as directly from C code
Page: https://docs.python.org/3/library/threading.html
Context: Python

Instruction: Thread(
  target, name, args,
  kwargs,
  daemon
)
Page: https://docs.python.org/3/library/threading.html
Returns: Create a thread, with name name, whether it's daemon, it'll run target(  *args, **kwargs)

Instruction: t.run()
Page: https://docs.python.org/3/library/threading.html
Effect: invokes the callable object passed to the object’s constructor as the target argument, if any, with positional and keyword arguments taken from the args and kwargs arguments, respectively.
Variables: t a thread

Instruction: t.join(foo)
Page: https://docs.python.org/3/library/threading.html
Effect: wait until t ends, or until foo seconds occurred
Variables: t a thread

Instruction: t.ident
Page: https://docs.python.org/3/library/threading.html
Returns: Thread identifier, or None if it is not started
Variables: t a thread

Instruction: t.daemon
Page: https://docs.python.org/3/library/threading.html
Returns: Whether t is a daemon
Variables: t a thread

Instruction: l.acquire()
Page: https://docs.python.org/3/library/threading.html
Returns: As soon as l is unlocked, locks l and returns.
Variables: l a lock object

Instruction: l.release()
Page: https://docs.python.org/3/library/threading.html
Returns: Unlock l
Variables: l a lock object
Exception: RuntimeError, if l is not locked

Typ: Lock
Meaning: primitive lock objects
Language: Python
Library: theading

Instruction: l.acquire(timeout = foo)
Page: https://docs.python.org/3/library/threading.html
Effect: lock l as soon as it is unlocked. Wait for foo second at most.
Variables: l.acquire
Library: theading

Instruction: l.acquire(blocking = False)
Page: https://docs.python.org/3/library/threading.html
Effect: Lock l if it is unlocked, do not wait anyway
Variables: l a primitive lock
Library: theading

Typ: RLock
Meaning: a synchronization primitive that may be acquired multiple times by the same thread without locking. It should be realeased as many time too, in order to unlock the lock
Language: Python
Name: A Reentrant lock
Library: theading

Instruction: rl.acquire()
Page: https://docs.python.org/3/library/threading.html
Returns: Call the acquire of the underlying lock
Variables: rl a RLock
Library: theading

Instruction: rl.release()
Page: https://docs.python.org/3/library/threading.html
Returns: Call the release of the underlying lock
Variables: rl a RLock
Library: theading

Instruction: rl.wait()
Page: https://docs.python.org/3/library/threading.html
Effect: releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all() call for the same condition variable in another thread, or until the optional timeout occurs. Once awakened or timed out, it re-acquires the lock and returns.
Variables: rl a RLock
Library: theading

Instruction: rl.wait(timeout)
Page: https://docs.python.org/3/library/threading.html
Effect: releases the underlying lock, and then blocks until it is awakened by a notify() or notify_all(), or at moste timeout second.
Call for the same condition variable in another thread, or until the optional timeout occurs. Once awakened or timed out, it re-acquires the lock and returns.
Variables: rl a RLock
Library: theading

Instruction: rl.wait_for(foo, timeout = s)
Page: https://docs.python.org/3/library/threading.html
Effect: Same as rl.wait_for(timeout = s), but each time wait would returns, foo is evaluated. If it's falsy, then wait restarts
Returns: last return value of foo. False if timeout
Variables: rl a RLock
Library: threading

Instruction: rl.notify(n=1)
Page: https://docs.python.org/3/library/threading.html
Effect: Wake up at most n threads waiting for the condition variable
Variables: rl a RLock
Library: theading

Instruction: rl.notify_all()
Page: https://docs.python.org/3/library/threading.html
Effect: Wake up all threads waiting for the condition variable
Variables: rl a RLock
Library: theading

Typ: Semaphore(value=1)
Meaning: A semaphore, allowing value element to be aqcuired simultaneously
Language: Python
Variables: rl a RLock
Library: theading

Typ: BoundedSemaphore(value=1)
Meaning: A semaphore, allowing value element to be aqcuired simultaneously, and where the number of release is bounded by the number of acquire
Language: Python
Library: theading

Typ: Event
Meaning: An event manage, allowing to send data between two thread
Language: Python

Instruction: e.is_set()
Page: https://docs.python.org/3/library/threading.html
Returns: Whether the internal flag is true
Variables: e an Event

Instruction: e.set()
Page: https://docs.python.org/3/library/threading.html
Returns: Set the internal flag is true
Variables: e an Event

Instruction: e.clear()
Page: https://docs.python.org/3/library/threading.html
Returns: Set the internal flag is false
Variables: e an Event

Instruction: e.wait(timeout)
Page: https://docs.python.org/3/library/threading.html
Effect: Wait at least timeout or until e is true
Variables: e an Event

Typ: Timer(interval, function, args, kwargs)
Meaning: A thread which will execute its method after interval seconds
Language: Python

Instruction: t.cancel()
Page: https://docs.python.org/3/library/threading.html
Effect: Cancel the waiting, the thread won't be executed
Variables: t: Timer object

Instruction: Barrier(
  parties,
  action=None,
  timeout=None
)
Page: https://docs.python.org/3/library/threading.html
Effect: A thread such that until parties element are waiting, and release them simultaneously. By default, all element wait timeout seconds

Instruction: b.wait(timeout)
Page: https://docs.python.org/3/library/threading.html
Effect: Release when parties thread have called this method.
Potentially execute action, but only one thread do it
Returns: A number between 0 and parties-1 unique for each
Variables: b a Barrier(parties, action=None, timeout=None)
Exception: BrokenBarrierError if:
* timeout seconds passed without parties thread joining
* another call b.reset or b.abort

Instruction: b.reset()
Page: https://docs.python.org/3/library/threading.html
Returns: The barrier to the default, empty state. Any threads waiting on it will receive the BrokenBarrierError exception.
Variables: b a Barrier(parties, action=None, timeout=None)

Instruction: b.abort()
Page: https://docs.python.org/3/library/threading.html
Effect: Put the barrier into a broken state. This causes any active or future calls to wait() to fail with the BrokenBarrierError.
Variables: b a Barrier(parties, action=None, timeout=None)

Instruction: b.n_waiting
Page: https://docs.python.org/3/library/threading.html
Effect: The number of threads currently waiting in the barrier.
Variables: b a Barrier(parties, action=None, timeout=None)

Instruction: b.broken
Page: https://docs.python.org/3/library/threading.html
Effect: Whether b is broken
Variables: b a Barrier(parties, action=None, timeout=None)

Instruction: BrokenBarrierError
Page: https://docs.python.org/3/library/threading.html
Returns: Exception raised when barrier broke, sent to thread waiting
Library: threading

Instruction: Queue()
Page: https://docs.python.org/3/library/queue.html
Returns: An unbounded FIFO queue

Instruction: LifoQueue()
Page: https://docs.python.org/3/library/queue.html
Returns: An unbounded LIFO queue

Instruction: PriorityQueue()
Page: https://docs.python.org/3/library/queue.html
Returns: An unbounded priority queue

Instruction: Queue/LifoQueue/PriorityQueue(maxsize)
Page: https://docs.python.org/3/library/queue.html
Returns: A FIFO/lifo/priority queue with at most maxsize element

Instruction: SimpleQueue
Page: https://docs.python.org/3/library/queue.html
Returns: A FIFO queue with less feature and more potentiallity than Queue

Instruction: Empty
Page: https://docs.python.org/3/library/queue.html
Context: queue
Returns: Exception raised when non-blocking get() (or get_nowait()) is called on a Queue object which is empty.

Instruction: Full
Page: https://docs.python.org/3/library/queue.html
Context: queue
Returns: Exception raised when non-blocking put() (or put_nowait()) is called on a Queue object which is full.

Instruction: qsize()
Page: https://docs.python.org/3/library/queue.html
Returns: approximate size of the queue
Variables: q some queue

Instruction: empty()
Page: https://docs.python.org/3/library/queue.html
Returns: Whether queue is empty
Variables: q some queue

Instruction: q.full()
Page: https://docs.python.org/3/library/queue.html
Returns: Whether queue is full
Variables: q some queue

Instruction: q.put(item)
Page: https://docs.python.org/3/library/queue.html
Effect: Wait until there is place in q and put item in it
Variables: q some queue

Instruction: q.put(
  item,
  block = False
)
Page: https://docs.python.org/3/library/queue.html
Effect: Put item in it
Variables: q some queue
Abbreviation: q.put_nowait(
  item
)
Example: Full if queue is full

Instruction: q.put(
  item,
  timeout = None
)
Page: https://docs.python.org/3/library/queue.html
Effect: Put item in the queue
Variables: q some queue
Example: Full,
  if there is no space during those timeout seconds

Instruction: q.get(block=False)
Page: https://docs.python.org/3/library/queue.html
Effect: Remove an item from the queue
Returns: an item from the queue
Variables: q some queue
Abbreviation: q.get_nowait()
Exception: Empty if there is nothing in the queue

Instruction: q.get(timeout=None)
Page: https://docs.python.org/3/library/queue.html
Effect: Remove an item from the queue; waiting at most timeout seconds
Returns: an item from the queue
Variables: q some queue
Exception: Empty if timeout second spent

Instruction: q.task_done()
Page: https://docs.python.org/3/library/queue.html
Effect: Indicate that a formerly enqueued task is complete
Variables: q some queue
Exception: ValueError if called more times than there were items placed in the queue.

Instruction: q.join()
Page: https://docs.python.org/3/library/queue.html
Effect: Waits until there are as many task_done as item added to the queue
Variables: q some queue