From 41a8f7e94c5f6e46e177ccfb9d1f37e2aa1f4858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 24 Aug 2023 14:32:02 +0200 Subject: [PATCH] Threading, Operator --- README.md | 17 ++++++++--------- index.html | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1366a6c..413140f 100644 --- a/README.md +++ b/README.md @@ -598,8 +598,7 @@ from dateutil.tz import tzlocal, gettz, datetime_exists, resolve_imaginary
= datetime(year, month, day, hour=0) # Also: `minute=0, second=0, microsecond=0, …`. = timedelta(weeks=0, days=0, hours=0) # Also: `minutes=0, seconds=0, microseconds=0`. ``` -* **Aware `` time and datetime objects have defined timezone, while naive `` don't.** -* **If object is naive, it is presumed to be in the system's timezone.** +* **Aware `` time and datetime objects have defined timezone, while naive `` don't. If object is naive, it is presumed to be in the system's timezone!** * **`'fold=1'` means the second pass in case of time jumping back for one hour.** * **Timedelta normalizes arguments to ±days, seconds (< 86 400) and microseconds (< 1M).** * **Use `'.weekday()'` to get the day of the week as an int, with Monday being 0.** @@ -2031,7 +2030,7 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03' Array ----- -**List that can only hold numbers of a predefined type. Available types and their minimum sizes in bytes are listed above. Sizes and byte order are always determined by the system, however bytes of each element can be swapped with byteswap() method.** +**List that can only hold numbers of a predefined type. Available types and their minimum sizes in bytes are listed above. Type sizes and byte order are always determined by the system, however bytes of each element can be swapped with byteswap() method.** ```python from array import array @@ -2090,10 +2089,9 @@ from collections import deque Threading --------- -* **CPython interpreter can only run a single thread at a time.** -* **That is why using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.** +* **CPython interpreter can only run a single thread at a time. Using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.** ```python -from threading import Thread, RLock, Semaphore, Event, Barrier +from threading import Thread, Timer, RLock, Semaphore, Event, Barrier from concurrent.futures import ThreadPoolExecutor, as_completed ``` @@ -2106,6 +2104,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed ``` * **Use `'kwargs='` to pass keyword arguments to the function.** * **Use `'daemon=True'`, or the program will not be able to exit while the thread is alive.** +* **To delay thread execution use `'Timer(, )'` instead of Thread().** ### Lock ```python @@ -2129,7 +2128,7 @@ with : # Enters the block by calling acq ### Queue ```python - = queue.Queue(maxsize=0) # A thread-safe FIFO queue. Also LifoQueue. + = queue.Queue(maxsize=0) # A thread-safe first-in-first-out queue. .put() # Blocks until queue stops being full. .put_nowait() # Raises queue.Full exception if full. = .get() # Blocks until queue stops being empty. @@ -2160,8 +2159,8 @@ Operator **Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.** ```python import operator as op - = op.not_() # not (or/and are not provided) - = op.eq/ne/lt/le/gt/ge/contains(, ) # ==, !=, <, <=, >, >=, in + = op.not_() # or, and (both missing), not + = op.eq/ne/lt/le/gt/ge/contains/is_(, ) # ==, !=, <, <=, >, >=, in, is = op.or_/xor/and_(, ) # |, ^, & = op.add/sub/mul/truediv/floordiv/mod(, ) # +, -, *, /, //, % = op.neg/invert() # -, ~ diff --git a/index.html b/index.html index a1e5cb8..89db64e 100644 --- a/index.html +++ b/index.html @@ -527,8 +527,7 @@ Point(x=1, y=2 <TD> = timedelta(weeks=0, days=0, hours=0) # Also: `minutes=0, seconds=0, microseconds=0`.
from threading import Thread, Timer, RLock, Semaphore, Event, Barrier
 from concurrent.futures import ThreadPoolExecutor, as_completed
 
@@ -1745,6 +1743,7 @@ CompletedProcess(args=['bc', 'kwargs=<dict>' to pass keyword arguments to the function.
  • Use 'daemon=True', or the program will not be able to exit while the thread is alive.
  • +
  • To delay thread execution use 'Timer(<float>, <func>)' instead of Thread().
  • Lock

    <lock> = RLock()                               # Lock that can only be released by acquirer.
     <lock>.acquire()                               # Waits for the lock to be available.
    @@ -1760,7 +1759,7 @@ CompletedProcess(args=['bc', # Wait() blocks until it's called n_times.
     
    -

    Queue

    <Queue> = queue.Queue(maxsize=0)               # A thread-safe FIFO queue. Also LifoQueue.
    +

    Queue

    <Queue> = queue.Queue(maxsize=0)               # A thread-safe first-in-first-out queue.
     <Queue>.put(<el>)                              # Blocks until queue stops being full.
     <Queue>.put_nowait(<el>)                       # Raises queue.Full exception if full.
     <el> = <Queue>.get()                           # Blocks until queue stops being empty.
    @@ -1784,8 +1783,8 @@ CompletedProcess(args=['bc', pickable. Queues must be sent using executor's 'initargs' and 'initializer' parameters.
     
     

    #Operator

    Module of functions that provide the functionality of operators. Functions are ordered by operator precedence, starting with least binding.

    import operator as op
    -<bool> = op.not_(<obj>)                                        # not (or/and are not provided)
    -<bool> = op.eq/ne/lt/le/gt/ge/contains(<obj>, <obj>)           # ==, !=, <, <=, >, >=, in
    +<bool> = op.not_(<obj>)                                        # or, and (both missing), not
    +<bool> = op.eq/ne/lt/le/gt/ge/contains/is_(<obj>, <obj>)       # ==, !=, <, <=, >, >=, in, is
     <obj>  = op.or_/xor/and_(<int/set>, <int/set>)                 # |, ^, &
     <obj>  = op.add/sub/mul/truediv/floordiv/mod(<obj>, <obj>)     # +, -, *, /, //, %
     <num>  = op.neg/invert(<num>)                                  # -, ~