@ -2148,7 +2148,7 @@ with <lock>: # Enters the block by calling acq
<bool> = <Future>.done() # Checks if the thread has finished executing.
<obj> = <Future>.result(timeout=None) # Waits for thread to finish and returns result.
<bool> = <Future>.cancel() # Cancels or returns False if running/finished.
<iter> = as_completed(<coll_of_Futures>) # Each Future is yielded as it completes.
<iter> = as_completed(<coll_of_Futures>) # Next() waits for next completed Future.
```
* **Map() and as_completed() also accept 'timeout' argument that causes TimeoutError if result isn't available in 'timeout' seconds after next() is called.**
* **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
<bool> = op.not_(<obj>) # or, and, not (or/and missing)
<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.**
* **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>
<obj> = <Future>.result(timeout=<spanclass="hljs-keyword">None</span>) <spanclass="hljs-comment"># Waits for thread to finish and returns result.</span>
<bool> = <Future>.cancel() <spanclass="hljs-comment"># Cancels or returns False if running/finished.</span>
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Each Future is yielded as it completes.</span>
<iter> = as_completed(<coll_of_Futures>) <spanclass="hljs-comment"># Next() waits for next completed Future.</span>
</code></pre>
<ul>
<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>
<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>
logging.debug/info/warning/error/critical(<str>) <spanclass="hljs-comment"># Logs to the root logger.</span>
<Logger> = logging.getLogger(__name__) <spanclass="hljs-comment"># Logger named after the module.</span>
<Logger>.<level>(<str>) <spanclass="hljs-comment"># Logs to the logger.</span>
<Logger>.exception(<str>) <spanclass="hljs-comment"># Calls error() with caught exception.</span>
<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>
logging.debug/info/warning/error/critical(<str>) <spanclass="hljs-comment"># Logs to the root logger.</span>
<Logger> = logging.getLogger(__name__) <spanclass="hljs-comment"># Logger named after the module.</span>
<Logger>.<level>(<str>) <spanclass="hljs-comment"># Logs to the logger.</span>
<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>
format=<spanclass="hljs-string">'%(levelname)s:%(name)s:%(message)s'</span>, <spanclass="hljs-comment"># Add `%(asctime)s` for local datetime.</span>
level=logging.WARNING, <spanclass="hljs-comment"># Drops messages with lower priority.</span>
handlers=[logging.StreamHandler()] <spanclass="hljs-comment"># Uses FileHandler if filename is set.</span>
filename=<spanclass="hljs-keyword">None</span>, <spanclass="hljs-comment"># Logs to console (stderr) by default.</span>
format=<spanclass="hljs-string">'%(levelname)s:%(name)s:%(message)s'</span>, <spanclass="hljs-comment"># Add `%(asctime)s` for local datetime.</span>
level=logging.WARNING, <spanclass="hljs-comment"># Drops messages with lower priority.</span>
handlers=[logging.StreamHandler()] <spanclass="hljs-comment"># Uses FileHandler if filename is set.</span>
)
</code></pre></div>
<pre><codeclass="python language-python hljs"><Formatter> = logging.Formatter(<spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Creates a Formatter.</span>
<Handler> = logging.FileHandler(<path>) <spanclass="hljs-comment"># Creates a Handler.</span>
<Handler>.setFormatter(<Formatter>) <spanclass="hljs-comment"># Adds Formatter to the Handler.</span>
<Handler>.setLevel(<int/str>) <spanclass="hljs-comment"># Processes all messages by default.</span>
<Logger>.addHandler(<Handler>) <spanclass="hljs-comment"># Adds Handler to the Logger.</span>
<Logger>.setLevel(<int/str>) <spanclass="hljs-comment"># What is sent to its/ancestor's handlers.</span>
<pre><codeclass="python language-python hljs"><Formatter> = logging.Formatter(<spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Creates a Formatter.</span>
<Handler> = logging.FileHandler(<path>) <spanclass="hljs-comment"># Creates a Handler.</span>
<Handler>.setFormatter(<Formatter>) <spanclass="hljs-comment"># Adds Formatter to the Handler.</span>
<Handler>.setLevel(<int/str>) <spanclass="hljs-comment"># Processes all messages by default.</span>
<Logger>.addHandler(<Handler>) <spanclass="hljs-comment"># Adds Handler to the Logger.</span>
<Logger>.setLevel(<int/str>) <spanclass="hljs-comment"># What is sent to its/ancestor's handlers.</span>
</code></pre>
<ul>
<li><strong>Parent logger can be specified by naming the child logger <codeclass="python hljs"><spanclass="hljs-string">'<parent>.<name>'</span></code>.</strong></li>
<li><strong>If logger doesn't have a set level it inherits it from the first ancestor that does.</strong></li>
<li><strong>Formatter also supports: pathname, filename, funcName, lineno, thread and process.</strong></li>
<li><strong>Formatter also accepts: pathname, filename, funcName, lineno, thread and process.</strong></li>
<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>
</ul>
<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>)