@@ -1857,30 +1857,74 @@ handler type) for messages from different processes to get mixed up.
18571857 Returns the logger used by :mod: `multiprocessing `. If necessary, a new one
18581858 will be created.
18591859
1860- When first created the logger has level :data: `logging.NOTSET ` and has a
1861- handler which sends output to :data: `sys.stderr ` using format
1862- ``'[%(levelname)s/%(processName)s] %(message)s' ``. (The logger allows use of
1863- the non-standard ``'%(processName)s' `` format.) Message sent to this logger
1864- will not by default propagate to the root logger.
1860+ When first created the logger has level :data: `logging.NOTSET ` and no
1861+ default handler. Messages sent to this logger will not by default propagate
1862+ to the root logger.
18651863
18661864 Note that on Windows child processes will only inherit the level of the
18671865 parent process's logger -- any other customization of the logger will not be
18681866 inherited.
18691867
1868+ .. currentmodule :: multiprocessing
1869+ .. function :: log_to_stderr()
1870+
1871+ This function performs a call to :func: `get_logger ` but in addition to
1872+ returning the logger created by get_logger, it adds a handler which sends
1873+ output to :data: `sys.stderr ` using format
1874+ ``'[%(levelname)s/%(processName)s] %(message)s' ``.
1875+
18701876Below is an example session with logging turned on::
18711877
18721878 >>> import multiprocessing, logging
1873- >>> logger = multiprocessing.get_logger ()
1879+ >>> logger = multiprocessing.log_to_stderr ()
18741880 >>> logger.setLevel(logging.INFO)
18751881 >>> logger.warning('doomed')
18761882 [WARNING/MainProcess] doomed
18771883 >>> m = multiprocessing.Manager()
18781884 [INFO/SyncManager-1] child process calling self.run()
1879- [INFO/SyncManager-1] manager bound to '\\\\.\\pipe\\pyc-2776-0-lj0tfa'
1885+ [INFO/SyncManager-1] created temp directory /.../pymp-Wh47O_
1886+ [INFO/SyncManager-1] manager serving at '/.../listener-lWsERs'
18801887 >>> del m
18811888 [INFO/MainProcess] sending shutdown message to manager
18821889 [INFO/SyncManager-1] manager exiting with exitcode 0
18831890
1891+ In addition to having these two logging functions, the multiprocessing also
1892+ exposes two additional logging level attributes. These are :const: `SUBWARNING `
1893+ and :const: `SUBDEBUG `. The table below illustrates where theses fit in the
1894+ normal level hierarchy.
1895+
1896+ +----------------+----------------+
1897+ | Level | Numeric value |
1898+ +================+================+
1899+ | ``SUBWARNING `` | 25 |
1900+ +----------------+----------------+
1901+ | ``SUBDEBUG `` | 5 |
1902+ +----------------+----------------+
1903+
1904+ For a full table of logging levels, see the :mod: `logging ` module.
1905+
1906+ These additional logging levels are used primarily for certain debug messages
1907+ within the multiprocessing module. Below is the same example as above, except
1908+ with :const: `SUBDEBUG ` enabled::
1909+
1910+ >>> import multiprocessing, logging
1911+ >>> logger = multiprocessing.log_to_stderr()
1912+ >>> logger.setLevel(multiprocessing.SUBDEBUG)
1913+ >>> logger.warning('doomed')
1914+ [WARNING/MainProcess] doomed
1915+ >>> m = multiprocessing.Manager()
1916+ [INFO/SyncManager-1] child process calling self.run()
1917+ [INFO/SyncManager-1] created temp directory /.../pymp-djGBXN
1918+ [INFO/SyncManager-1] manager serving at '/.../pymp-djGBXN/listener-knBYGe'
1919+ >>> del m
1920+ [SUBDEBUG/MainProcess] finalizer calling ...
1921+ [INFO/MainProcess] sending shutdown message to manager
1922+ [DEBUG/SyncManager-1] manager received shutdown message
1923+ [SUBDEBUG/SyncManager-1] calling <Finalize object, callback=unlink, ...
1924+ [SUBDEBUG/SyncManager-1] finalizer calling <built-in function unlink> ...
1925+ [SUBDEBUG/SyncManager-1] calling <Finalize object, dead>
1926+ [SUBDEBUG/SyncManager-1] finalizer calling <function rmtree at 0x5aa730> ...
1927+ [INFO/SyncManager-1] manager exiting with exitcode 0
18841928
18851929The :mod: `multiprocessing.dummy ` module
18861930~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments