mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #19882: tweak docs for socket.close()
This commit is contained in:
parent
abbc8ca708
commit
e3658a70c3
1 changed files with 19 additions and 9 deletions
|
@ -701,8 +701,9 @@ The module :mod:`socket` exports the following constants and functions:
|
||||||
Socket Objects
|
Socket Objects
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
Socket objects have the following methods. Except for :meth:`makefile` these
|
Socket objects have the following methods. Except for
|
||||||
correspond to Unix system calls applicable to sockets.
|
:meth:`~socket.makefile`, these correspond to Unix system calls applicable
|
||||||
|
to sockets.
|
||||||
|
|
||||||
|
|
||||||
.. method:: socket.accept()
|
.. method:: socket.accept()
|
||||||
|
@ -721,9 +722,15 @@ correspond to Unix system calls applicable to sockets.
|
||||||
|
|
||||||
.. method:: socket.close()
|
.. method:: socket.close()
|
||||||
|
|
||||||
Close the socket. All future operations on the socket object will fail. The
|
Mark the socket closed. The underlying system resource (e.g. a file
|
||||||
remote end will receive no more data (after queued data is flushed). Sockets are
|
descriptor) is also closed when all file objects from :meth:`makefile()`
|
||||||
automatically closed when they are garbage-collected.
|
are closed. Once that happens, all future operations on the socket
|
||||||
|
object will fail. The remote end will receive no more data (after
|
||||||
|
queued data is flushed).
|
||||||
|
|
||||||
|
Sockets are automatically closed when they are garbage-collected, but
|
||||||
|
it is recommended to :meth:`close` them explicitly, or to use a
|
||||||
|
:keyword:`with` statement around them.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
:meth:`close()` releases the resource associated with a connection but
|
:meth:`close()` releases the resource associated with a connection but
|
||||||
|
@ -829,10 +836,13 @@ correspond to Unix system calls applicable to sockets.
|
||||||
type depends on the arguments given to :meth:`makefile`. These arguments are
|
type depends on the arguments given to :meth:`makefile`. These arguments are
|
||||||
interpreted the same way as by the built-in :func:`open` function.
|
interpreted the same way as by the built-in :func:`open` function.
|
||||||
|
|
||||||
Closing the file object won't close the socket unless there are no remaining
|
The socket must be in blocking mode; it can have a timeout, but the file
|
||||||
references to the socket. The socket must be in blocking mode; it can have
|
object's internal buffer may end up in a inconsistent state if a timeout
|
||||||
a timeout, but the file object's internal buffer may end up in a inconsistent
|
occurs.
|
||||||
state if a timeout occurs.
|
|
||||||
|
Closing the file object returned by :meth:`makefile` won't close the
|
||||||
|
original socket unless all other file objects have been closed and
|
||||||
|
:meth:`socket.close` has been called on the socket object.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue