PEP 475: update the list of modified functions according to the implementation

Mention also the special case of socket.socket.connect().
This commit is contained in:
Victor Stinner 2015-04-19 10:59:06 +02:00
parent 6c32726275
commit c170883653
1 changed files with 59 additions and 22 deletions

View File

@ -168,37 +168,74 @@ Modified functions
Example of standard library functions that need to be modified to comply Example of standard library functions that need to be modified to comply
with this PEP: with this PEP:
* ``open()``, ``os.open()`` * ``open()``, ``os.open()``, ``io.open()``
* ``os.read()``, ``io.FileIO.read()``, ``io.FileIO.readinto()`` * functions of the ``faulthandler`` module
* ``os.write()``, ``io.FileIO.write()`` * ``os`` functions:
* ``os.waitpid()``
* ``socket.accept()``
* ``socket.connect()``
* ``socket.recv()``, ``socket.recv_into()``
* ``socket.recv_from()``
* ``socket.send()``
* ``socket.sendto()``
* ``time.sleep()``
* ``select.select()``
* ``select.poll()``
* ``select.epoll.poll()``
* ``select.devpoll.poll()``
* ``select.kqueue.control()``
* ``selectors.SelectSelector.select()`` and other selector classes
(note: the ``selector`` module already retries on ``InterruptedError``, but it - ``os.fchdir()``
- ``os.fchmod()``
- ``os.fchown()``
- ``os.fdatasync()``
- ``os.fstat()``
- ``os.fstatvfs()``
- ``os.fsync()``
- ``os.ftruncate()``
- ``os.mkfifo()``
- ``os.mknod()``
- ``os.posix_fadvise()``
- ``os.posix_fallocate()``
- ``os.pread()``
- ``os.pwrite()``
- ``os.read()``
- ``os.readv()``
- ``os.sendfile()``
- ``os.wait3()``
- ``os.wait4()``
- ``os.wait()``
- ``os.waitid()``
- ``os.waitpid()``
- ``os.write()``
- ``os.writev()``
- special cases: ``os.close()`` and ``os.dup2()`` now ignore ``EINTR`` error,
the syscall is not retried
* ``select.select()``, ``select.poll.poll()``, ``select.epoll.poll()``,
``select.kqueue.control()``, ``select.devpoll.poll()``
* ``socket.socket()`` methods:
- ``accept()``
- ``connect()`` (except for non-blocking sockets)
- ``recv()``
- ``recvfrom()``
- ``recvmsg()``
- ``send()``
- ``sendall()``
- ``sendmsg()``
- ``sendto()``
* ``signal.sigtimedwait()``, ``signal.sigwaitinfo()``
* ``time.sleep()``
(Note: the ``selector`` module already retries on ``InterruptedError``, but it
doesn't recompute the timeout yet) doesn't recompute the timeout yet)
``os.close`` and ``close()`` methods are a special case: they will ignore ``os.close``, ``close()`` methods and ``os.dup2()`` are a special case: they
EINTR instead of retrying. The reason is complex but involves behaviour will ignore ``EINTR`` instead of retrying. The reason is complex but involves
under Linux and the fact that the file descriptor may really be closed behaviour under Linux and the fact that the file descriptor may really be
even if EINTR is returned. See articles: closed even if EINTR is returned. See articles:
* `Returning EINTR from close() <http://lwn.net/Articles/576478/>`_ * `Returning EINTR from close() <http://lwn.net/Articles/576478/>`_
* `(LKML) Re: [patch 7/7] uml: retry host close() on EINTR * `(LKML) Re: [patch 7/7] uml: retry host close() on EINTR
<http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html>`_ <http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html>`_
* `close() and EINTR <http://alobbs.com/post/54503240599/close-and-eintr>`_ * `close() and EINTR <http://alobbs.com/post/54503240599/close-and-eintr>`_
The ``socket.socket.connect()`` method does not retry ``connect()`` for
non-blocking sockets if it is interrupted by a signal (fails with ``EINTR``).
The connection runs asynchronously in background. The caller is responsible
to wait until the socket becomes writable (ex: using ``select.select()``)
and then call ``socket.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)``
to check if the connection succeeded (``getsockopt()`` returns ``0``) or failed.
InterruptedError handling InterruptedError handling
------------------------- -------------------------