Skip to content

Commit

Permalink
Merge pull request #1 from python/master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
aeros authored Jul 4, 2019
2 parents 80097e0 + b607d99 commit 3e4e456
Show file tree
Hide file tree
Showing 160 changed files with 2,330 additions and 978 deletions.
21 changes: 11 additions & 10 deletions Doc/c-api/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ bound into a function.
Return the number of free variables in *co*.
.. c:function:: PyCodeObject* PyCode_New(int argcount, int posonlyargcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
.. c:function:: PyCodeObject* PyCode_New(int argcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
Return a new code object. If you need a dummy code object to
create a frame, use :c:func:`PyCode_NewEmpty` instead. Calling
:c:func:`PyCode_New` directly can bind you to a precise Python
version since the definition of the bytecode changes often.
.. versionchanged:: 3.8
An extra parameter is required (*posonlyargcount*) to support :PEP:`570`.
The first parameter (*argcount*) now represents the total number of positional arguments,
including positional-only.
Return a new code object. If you need a dummy code object to create a frame,
use :c:func:`PyCode_NewEmpty` instead. Calling :c:func:`PyCode_New` directly
can bind you to a precise Python version since the definition of the bytecode
changes often.
.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags c.PyCode_New
.. c:function:: PyCodeObject* PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount, int nlocals, int stacksize, int flags, PyObject *code, PyObject *consts, PyObject *names, PyObject *varnames, PyObject *freevars, PyObject *cellvars, PyObject *filename, PyObject *name, int firstlineno, PyObject *lnotab)
Similar to :c:func:`PyCode_New`, but with an extra "posonlyargcount" for positonal-only arguments.
.. versionadded:: 3.8
.. c:function:: PyCodeObject* PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
Return a new empty code object with the specified filename,
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ an error value).
:mod:`warnings` module and the :option:`-W` option in the command line
documentation. There is no C API for warning control.
.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *msg, PyObject *name, PyObject *path)
.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, PyObject *name, PyObject *path)
Much like :c:func:`PyErr_SetImportError` but this function allows for
specifying a subclass of :exc:`ImportError` to raise.
Expand Down
7 changes: 7 additions & 0 deletions Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Functions:
* :c:func:`PyConfig_SetBytesArgv`
* :c:func:`PyConfig_SetBytesString`
* :c:func:`PyConfig_SetString`
* :c:func:`PyConfig_SetWideStringList`
* :c:func:`PyPreConfig_InitIsolatedConfig`
* :c:func:`PyPreConfig_InitPythonConfig`
* :c:func:`PyStatus_Error`
Expand Down Expand Up @@ -368,6 +369,12 @@ PyConfig
Preinitialize Python if needed.
.. c:function:: PyStatus PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list, Py_ssize_t length, wchar_t **items)
Set the list of wide strings *list* to *length* and *items*.
Preinitialize Python if needed.
.. c:function:: PyStatus PyConfig_Read(PyConfig *config)
Read all Python configuration.
Expand Down
19 changes: 18 additions & 1 deletion Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,26 @@ PyCode_Check:PyObject*:co:0:
PyCode_GetNumFree:int:::
PyCode_GetNumFree:PyCodeObject*:co:0:

PyCode_NewWithPosOnlyArgs:PyCodeObject*::+1:
PyCode_NewWithPosOnlyArgs:int:argcount::
PyCode_NewWithPosOnlyArgs:int:posonlyargcount::
PyCode_NewWithPosOnlyArgs:int:kwonlyargcount::
PyCode_NewWithPosOnlyArgs:int:nlocals::
PyCode_NewWithPosOnlyArgs:int:stacksize::
PyCode_NewWithPosOnlyArgs:int:flags::
PyCode_NewWithPosOnlyArgs:PyObject*:code:0:
PyCode_NewWithPosOnlyArgs:PyObject*:consts:0:
PyCode_NewWithPosOnlyArgs:PyObject*:names:0:
PyCode_NewWithPosOnlyArgs:PyObject*:varnames:0:
PyCode_NewWithPosOnlyArgs:PyObject*:freevars:0:
PyCode_NewWithPosOnlyArgs:PyObject*:cellvars:0:
PyCode_NewWithPosOnlyArgs:PyObject*:filename:0:
PyCode_NewWithPosOnlyArgs:PyObject*:name:0:
PyCode_NewWithPosOnlyArgs:int:firstlineno::
PyCode_NewWithPosOnlyArgs:PyObject*:lnotab:0:

PyCode_New:PyCodeObject*::+1:
PyCode_New:int:argcount::
PyCode_New:int:posonlyargcount::
PyCode_New:int:kwonlyargcount::
PyCode_New:int:nlocals::
PyCode_New:int:stacksize::
Expand Down
4 changes: 2 additions & 2 deletions Doc/distutils/builtdist.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ or the :command:`bdist` command with the :option:`!--formats` option::

If you have a pure module distribution (only containing pure Python modules and
packages), the resulting installer will be version independent and have a name
like :file:`foo-1.0.win32.exe`. These installers can even be created on Unix
platforms or Mac OS X.
like :file:`foo-1.0.win32.exe`. Note that creating ``wininst`` binary
distributions in only supported on Windows systems.

If you have a non-pure distribution, the extensions can only be created on a
Windows platform, and will be Python version dependent. The installer filename
Expand Down
6 changes: 3 additions & 3 deletions Doc/howto/logging-cookbook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2266,9 +2266,9 @@ The script just arranges to decorate ``foo`` with a decorator which will do the
conditional logging that's required. The decorator takes a logger as a parameter
and attaches a memory handler for the duration of the call to the decorated
function. The decorator can be additionally parameterised using a target handler,
a level at which flushing should occur, and a capacity for the buffer. These
default to a :class:`~logging.StreamHandler` which writes to ``sys.stderr``,
``logging.ERROR`` and ``100`` respectively.
a level at which flushing should occur, and a capacity for the buffer (number of
records buffered). These default to a :class:`~logging.StreamHandler` which
writes to ``sys.stderr``, ``logging.ERROR`` and ``100`` respectively.

Here's the script::

Expand Down
62 changes: 54 additions & 8 deletions Doc/library/asyncio-policy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ asyncio ships with the following built-in policies:

.. availability:: Windows.

.. _asyncio-watchers:

Process Watchers
================
Expand All @@ -129,10 +130,11 @@ In asyncio, child processes are created with
:func:`create_subprocess_exec` and :meth:`loop.subprocess_exec`
functions.

asyncio defines the :class:`AbstractChildWatcher` abstract base class,
which child watchers should implement, and has two different
implementations: :class:`SafeChildWatcher` (configured to be used
by default) and :class:`FastChildWatcher`.
asyncio defines the :class:`AbstractChildWatcher` abstract base class, which child
watchers should implement, and has four different implementations:
:class:`ThreadedChildWatcher` (configured to be used by default),
:class:`MultiLoopChildWatcher`, :class:`SafeChildWatcher`, and
:class:`FastChildWatcher`.

See also the :ref:`Subprocess and Threads <asyncio-subprocess-threads>`
section.
Expand Down Expand Up @@ -184,23 +186,64 @@ implementation used by the asyncio event loop:

Note: loop may be ``None``.

.. method:: is_active()

Return ``True`` if the watcher is ready to use.

Spawning a subprocess with *inactive* current child watcher raises
:exc:`RuntimeError`.

.. versionadded:: 3.8

.. method:: close()

Close the watcher.

This method has to be called to ensure that underlying
resources are cleaned-up.

.. class:: SafeChildWatcher
.. class:: ThreadedChildWatcher

This implementation starts a new waiting thread for every subprocess spawn.

It works reliably even when the asyncio event loop is run in a non-main OS thread.

There is no noticeable overhead when handling a big number of children (*O(1)* each
time a child terminates), but stating a thread per process requires extra memory.

This watcher is used by default.

.. versionadded:: 3.8

This implementation avoids disrupting other code spawning processes
.. class:: MultiLoopChildWatcher

This implementation registers a :py:data:`SIGCHLD` signal handler on
instantiation. That can break third-party code that installs a custom handler for
`SIGCHLD`. signal).

The watcher avoids disrupting other code spawning processes
by polling every process explicitly on a :py:data:`SIGCHLD` signal.

This is a safe solution but it has a significant overhead when
There is no limitation for running subprocesses from different threads once the
watcher is installed.

The solution is safe but it has a significant overhead when
handling a big number of processes (*O(n)* each time a
:py:data:`SIGCHLD` is received).

asyncio uses this safe implementation by default.
.. versionadded:: 3.8

.. class:: SafeChildWatcher

This implementation uses active event loop from the main thread to handle
:py:data:`SIGCHLD` signal. If the main thread has no running event loop another
thread cannot spawn a subprocess (:exc:`RuntimeError` is raised).

The watcher avoids disrupting other code spawning processes
by polling every process explicitly on a :py:data:`SIGCHLD` signal.

This solution is as safe as :class:`MultiLoopChildWatcher` and has the same *O(N)*
complexity but requires a running event loop in the main thread to work.

.. class:: FastChildWatcher

Expand All @@ -211,6 +254,9 @@ implementation used by the asyncio event loop:
There is no noticeable overhead when handling a big number of
children (*O(1)* each time a child terminates).

This solution requires a running event loop in the main thread to work, as
:class:`SafeChildWatcher`.


Custom Policies
===============
Expand Down
26 changes: 17 additions & 9 deletions Doc/library/asyncio-subprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,26 @@ their completion.
Subprocess and Threads
----------------------

Standard asyncio event loop supports running subprocesses from
different threads, but there are limitations:
Standard asyncio event loop supports running subprocesses from different threads by
default.

* An event loop must run in the main thread.
On Windows subprocesses are provided by :class:`ProactorEventLoop` only (default),
:class:`SelectorEventLoop` has no subprocess support.

* The child watcher must be instantiated in the main thread
before executing subprocesses from other threads. Call the
:func:`get_child_watcher` function in the main thread to instantiate
the child watcher.
On UNIX *child watchers* are used for subprocess finish waiting, see
:ref:`asyncio-watchers` for more info.

Note that alternative event loop implementations might not share
the above limitations; please refer to their documentation.

.. versionchanged:: 3.8

UNIX switched to use :class:`ThreadedChildWatcher` for spawning subprocesses from
different threads without any limitation.

Spawning a subprocess with *inactive* current child watcher raises
:exc:`RuntimeError`.

Note that alternative event loop implementations might have own limitations;
please refer to their documentation.

.. seealso::

Expand Down
5 changes: 5 additions & 0 deletions Doc/library/http.client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ The module provides the following classes:
:func:`ssl._create_unverified_context` can be passed to the *context*
parameter.

.. versionchanged:: 3.8
This class now enables TLS 1.3
:attr:`ssl.SSLContext.post_handshake_auth` for the default *context* or
when *cert_file* is passed with a custom *context*.

.. deprecated:: 3.6

*key_file* and *cert_file* are deprecated in favor of *context*.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/importlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ ABC hierarchy::
packages or a module).

Loaders that wish to support resource reading are expected to
provide a method called ``get_resource_loader(fullname)`` which
provide a method called ``get_resource_reader(fullname)`` which
returns an object implementing this ABC's interface. If the module
specified by fullname is not a package, this method should return
:const:`None`. An object compatible with this ABC should only be
Expand Down
65 changes: 40 additions & 25 deletions Doc/library/logging.handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and :meth:`flush` methods).
.. method:: emit(record)

If a formatter is specified, it is used to format the record. The record
is then written to the stream with a terminator. If exception information
is then written to the stream followed by :attr:`terminator`. If exception information
is present, it is formatted using :func:`traceback.print_exception` and
appended to the stream.

Expand All @@ -68,15 +68,19 @@ and :meth:`flush` methods).

:return: the old stream, if the stream was changed, or *None* if it wasn't.

.. versionadded:: 3.7
.. versionadded:: 3.7

.. attribute:: terminator

.. versionchanged:: 3.2
The ``StreamHandler`` class now has a ``terminator`` attribute, default
value ``'\n'``, which is used as the terminator when writing a formatted
record to a stream. If you don't want this newline termination, you can
set the handler instance's ``terminator`` attribute to the empty string.
In earlier versions, the terminator was hardcoded as ``'\n'``.
String used as the terminator when writing a formatted record to a stream.
Default value is ``'\n'``.

If you don't want a newline termination, you can set the handler instance's
``terminator`` attribute to the empty string.

In earlier versions, the terminator was hardcoded as ``'\n'``.

.. versionadded:: 3.2


.. _file-handler:
Expand Down Expand Up @@ -109,7 +113,6 @@ sends logging output to a disk file. It inherits the output functionality from

Closes the file.


.. method:: emit(record)

Outputs the record to the file.
Expand Down Expand Up @@ -858,7 +861,8 @@ should, then :meth:`flush` is expected to do the flushing.

.. class:: BufferingHandler(capacity)

Initializes the handler with a buffer of the specified capacity.
Initializes the handler with a buffer of the specified capacity. Here,
*capacity* means the number of logging records buffered.


.. method:: emit(record)
Expand All @@ -882,12 +886,13 @@ should, then :meth:`flush` is expected to do the flushing.
.. class:: MemoryHandler(capacity, flushLevel=ERROR, target=None, flushOnClose=True)

Returns a new instance of the :class:`MemoryHandler` class. The instance is
initialized with a buffer size of *capacity*. If *flushLevel* is not specified,
:const:`ERROR` is used. If no *target* is specified, the target will need to be
set using :meth:`setTarget` before this handler does anything useful. If
*flushOnClose* is specified as ``False``, then the buffer is *not* flushed when
the handler is closed. If not specified or specified as ``True``, the previous
behaviour of flushing the buffer will occur when the handler is closed.
initialized with a buffer size of *capacity* (number of records buffered).
If *flushLevel* is not specified, :const:`ERROR` is used. If no *target* is
specified, the target will need to be set using :meth:`setTarget` before this
handler does anything useful. If *flushOnClose* is specified as ``False``,
then the buffer is *not* flushed when the handler is closed. If not specified
or specified as ``True``, the previous behaviour of flushing the buffer will
occur when the handler is closed.

.. versionchanged:: 3.6
The *flushOnClose* parameter was added.
Expand Down Expand Up @@ -987,14 +992,21 @@ possible, while any potentially slow operations (such as sending an email via
.. class:: QueueHandler(queue)

Returns a new instance of the :class:`QueueHandler` class. The instance is
initialized with the queue to send messages to. The queue can be any
queue-like object; it's used as-is by the :meth:`enqueue` method, which needs
to know how to send messages to it.
initialized with the queue to send messages to. The *queue* can be any
queue-like object; it's used as-is by the :meth:`enqueue` method, which
needs to know how to send messages to it. The queue is not *required* to
have the task tracking API, which means that you can use
:class:`~queue.SimpleQueue` instances for *queue*.


.. method:: emit(record)

Enqueues the result of preparing the LogRecord.
Enqueues the result of preparing the LogRecord. Should an exception
occur (e.g. because a bounded queue has filled up), the
:meth:`~logging.Handler.handleError` method is called to handle the
error. This can result in the record silently being dropped (if
:attr:`logging.raiseExceptions` is ``False``) or a message printed to
``sys.stderr`` (if :attr:`logging.raiseExceptions` is ``True``).

.. method:: prepare(record)

Expand Down Expand Up @@ -1045,11 +1057,14 @@ possible, while any potentially slow operations (such as sending an email via
initialized with the queue to send messages to and a list of handlers which
will handle entries placed on the queue. The queue can be any queue-like
object; it's passed as-is to the :meth:`dequeue` method, which needs
to know how to get messages from it. If ``respect_handler_level`` is ``True``,
a handler's level is respected (compared with the level for the message) when
deciding whether to pass messages to that handler; otherwise, the behaviour
is as in previous Python versions - to always pass each message to each
handler.
to know how to get messages from it. The queue is not *required* to have the
task tracking API (though it's used if available), which means that you can
use :class:`~queue.SimpleQueue` instances for *queue*.

If ``respect_handler_level`` is ``True``, a handler's level is respected
(compared with the level for the message) when deciding whether to pass
messages to that handler; otherwise, the behaviour is as in previous Python
versions - to always pass each message to each handler.

.. versionchanged:: 3.5
The ``respect_handler_levels`` argument was added.
Expand Down
Loading

0 comments on commit 3e4e456

Please sign in to comment.