You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -2148,7 +2148,7 @@ with <lock>: # Enters the block by calling acq
2148
2148
<bool>=<Future>.done() # Checks if the thread has finished executing.
2149
2149
<obj>=<Future>.result(timeout=None) # Waits for thread to finish and returns result.
2150
2150
<bool>=<Future>.cancel() # Cancels or returns False if running/finished.
2151
-
<iter>= as_completed(<coll_of_Futures>) #Each Future is yielded as it completes.
2151
+
<iter>= as_completed(<coll_of_Futures>) #Next() waits for next completed Future.
2152
2152
```
2153
2153
***Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.**
2154
2154
***Exceptions that happen inside threads are raised when next() is called on map's iterator or when result() is called on a Future. Its exception() method returns exception or None.**
@@ -2163,6 +2163,7 @@ import operator as op
2163
2163
<bool>= op.not_(<obj>) # or, and, not (or/and missing)
2164
2164
<bool>= op.eq/ne/lt/le/gt/ge/contains/is_(<obj>, <obj>) # ==, !=, <, <=, >, >=, in, is
***Bitwise operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.**
2180
+
***Bitwise operators require objects to have or(), xor(), and(), lshift(), rshift() and invert() special methods, unlike logical operators that work on all types of objects.**
<pre><codeclass="python language-python hljs"><bool> = <Future>.done() <spanclass="hljs-comment"># Checks if the thread has finished executing.</span>
1775
1775
<obj> = <Future>.result(timeout=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
1776
1776
<bool> = <Future>.cancel() <spanclass="hljs-comment"># Cancels or returns False if running/finished.</span>
1777
-
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Each Future is yielded as it completes.</span>
1777
+
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Next() waits for next completed Future.</span>
1778
1778
</code></pre>
1779
1779
<ul>
1780
1780
<li><strong>Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.</strong></li>
<li><strong>Bitwise operators require objects to have and(), or(), xor() and invert() special methods, unlike logical operators that work on all types of objects.</strong></li>
1803
+
<li><strong>Bitwise operators require objects to have or(), xor(), and(), lshift(), rshift() and invert() special methods, unlike logical operators that work on all types of objects.</strong></li>
<pre><codeclass="python language-python hljs">logging.basicConfig(filename=<path>) <spanclass="hljs-comment"># Configures the root logger (see Setup).</span>
2016
-
logging.debug/info/warning/error/critical(<str>) <spanclass="hljs-comment"># Logs to the root logger.</span>
2017
-
<Logger> = logging.getLogger(__name__) <spanclass="hljs-comment"># Logger named after the module.</span>
2018
-
<Logger>.<level>(<str>) <spanclass="hljs-comment"># Logs to the logger.</span>
2019
-
<Logger>.exception(<str>) <spanclass="hljs-comment"># Calls error() with caught exception.</span>
2015
+
<pre><codeclass="python language-python hljs">logging.basicConfig(filename=<path>, level=<spanclass="hljs-string">'DEBUG'</span>)<spanclass="hljs-comment"># Configures the root logger (see Setup).</span>
2016
+
logging.debug/info/warning/error/critical(<str>) <spanclass="hljs-comment"># Logs to the root logger.</span>
2017
+
<Logger> = logging.getLogger(__name__) <spanclass="hljs-comment"># Logger named after the module.</span>
2018
+
<Logger>.<level>(<str>) <spanclass="hljs-comment"># Logs to the logger.</span>
2019
+
<Logger>.exception(<str>) <spanclass="hljs-comment"># Calls error() with caught exception.</span>
filename=<spanclass="hljs-keyword">None</span>, <spanclass="hljs-comment"># Logs to console (stderr) by default.</span>
2023
-
format=<spanclass="hljs-string">'%(levelname)s:%(name)s:%(message)s'</span>, <spanclass="hljs-comment"># Add `%(asctime)s` for local datetime.</span>
2024
-
level=logging.WARNING, <spanclass="hljs-comment"># Drops messages with lower priority.</span>
2025
-
handlers=[logging.StreamHandler()] <spanclass="hljs-comment"># Uses FileHandler if filename is set.</span>
2022
+
filename=<spanclass="hljs-keyword">None</span>, <spanclass="hljs-comment"># Logs to console (stderr) by default.</span>
2023
+
format=<spanclass="hljs-string">'%(levelname)s:%(name)s:%(message)s'</span>, <spanclass="hljs-comment"># Add `%(asctime)s` for local datetime.</span>
2024
+
level=logging.WARNING, <spanclass="hljs-comment"># Drops messages with lower priority.</span>
2025
+
handlers=[logging.StreamHandler()] <spanclass="hljs-comment"># Uses FileHandler if filename is set.</span>
2026
2026
)
2027
2027
</code></pre></div>
2028
2028
2029
-
<pre><codeclass="python language-python hljs"><Formatter> = logging.Formatter(<spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Creates a Formatter.</span>
2030
-
<Handler> = logging.FileHandler(<path>) <spanclass="hljs-comment"># Creates a Handler.</span>
2031
-
<Handler>.setFormatter(<Formatter>) <spanclass="hljs-comment"># Adds Formatter to the Handler.</span>
2032
-
<Handler>.setLevel(<int/str>) <spanclass="hljs-comment"># Processes all messages by default.</span>
2033
-
<Logger>.addHandler(<Handler>) <spanclass="hljs-comment"># Adds Handler to the Logger.</span>
2034
-
<Logger>.setLevel(<int/str>) <spanclass="hljs-comment"># What is sent to its/ancestor's handlers.</span>
2029
+
<pre><codeclass="python language-python hljs"><Formatter> = logging.Formatter(<spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Creates a Formatter.</span>
2030
+
<Handler> = logging.FileHandler(<path>) <spanclass="hljs-comment"># Creates a Handler.</span>
2031
+
<Handler>.setFormatter(<Formatter>) <spanclass="hljs-comment"># Adds Formatter to the Handler.</span>
2032
+
<Handler>.setLevel(<int/str>) <spanclass="hljs-comment"># Processes all messages by default.</span>
2033
+
<Logger>.addHandler(<Handler>) <spanclass="hljs-comment"># Adds Handler to the Logger.</span>
2034
+
<Logger>.setLevel(<int/str>) <spanclass="hljs-comment"># What is sent to its/ancestor's handlers.</span>
2035
2035
</code></pre>
2036
2036
<ul>
2037
2037
<li><strong>Parent logger can be specified by naming the child logger <codeclass="python hljs"><spanclass="hljs-string">'<parent>.<name>'</span></code>.</strong></li>
2038
2038
<li><strong>If logger doesn't have a set level it inherits it from the first ancestor that does.</strong></li>
2039
-
<li><strong>Formatter also supports: pathname, filename, funcName, lineno, thread and process.</strong></li>
2039
+
<li><strong>Formatter also accepts: pathname, filename, funcName, lineno, thread and process.</strong></li>
2040
2040
<li><strong>A <codeclass="python hljs"><spanclass="hljs-string">'handlers.RotatingFileHandler'</span></code> creates and deletes log files based on 'maxBytes' and 'backupCount' arguments.</strong></li>
2041
2041
</ul>
2042
2042
<div><h4id="createsaloggerthatwritesallmessagestofileandsendsthemtotherootshandlerthatprintswarningsorhigher">Creates a logger that writes all messages to file and sends them to the root's handler that prints warnings or higher:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>> </span>logger = logging.getLogger(<spanclass="hljs-string">'my_module'</span>)
0 commit comments