gevent._socket3 – Python 3 socket module

class socket(family=-1, type=-1, proto=-1, fileno=None)[source]

Bases: object

gevent socket.socket for Python 3.

This object should have the same API as the standard library socket linked to above. Not all methods are specifically documented here; when they are they may point out a difference to be aware of or may document a method the standard library does not.

accept() -> (socket object, address info)[source]

Wait for an incoming connection. Return a new socket representing the connection, and the address of the client. For IP sockets, the address info is a pair (hostaddr, port).

detach() → file descriptor[source]

Close the socket object without closing the underlying file descriptor. The object cannot be used after this call, but the file descriptor can be reused for other purposes. The file descriptor is returned.

dup() → socket object[source]

Return a new socket object connected to the same system resource.


Get the inheritable flag of the socket


Returns whether the socket will approximate blocking behaviour.

New in version 1.3a2: Added in Python 3.7.

makefile(mode='r', buffering=None, *, encoding=None, errors=None, newline=None)[source]

Return an I/O stream connected to the socket

The arguments are as for after the filename, except the only mode characters supported are ‘r’, ‘w’ and ‘b’. The semantics are similar too.

sendfile(file[, offset[, count]]) → sent[source]

Send a file until EOF is reached by using high-performance os.sendfile() and return the total number of bytes which were sent. file must be a regular file object opened in binary mode. If os.sendfile() is not available (e.g. Windows) or file is not a regular file socket.send() will be used instead. offset tells from where to start reading the file. If specified, count is the total number of bytes to transmit as opposed to sending the file until EOF is reached. File position is updated on return or also in case of error in which case file.tell() can be used to figure out the number of bytes which were sent. The socket must be of SOCK_STREAM type. Non-blocking sockets are not supported.

New in version 1.1rc4: Added in Python 3.5, but available under all Python 3 versions in gevent.


Set the inheritable flag of the socket


alias of gevent._socket3.socket

create_connection(address, timeout=None, source_address=None) → socket[source]

Connect to address and return the gevent.socket.socket object.

Convenience function. Connect to address (a 2-tuple (host, port)) and return the socket object. Passing the optional timeout parameter will set the timeout on the socket instance before attempting to connect. If no timeout is supplied, the global default timeout setting returned by getdefaulttimeout() is used. If source_address is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. A host of ‘’ or port 0 tells the OS to use the default.

fromfd(fd, family, type[, proto]) → socket object[source]

Create a socket object from a duplicate of the given file descriptor. The remaining arguments are the same as for socket().

socketpair([family[, type[, proto]]]) -> (socket object, socket object)[source]

Create a pair of socket objects from the sockets returned by the platform socketpair() function. The arguments are the same as for socket() except the default family is AF_UNIX if defined on the platform; otherwise, the default is AF_INET.

Changed in version 1.2: All Python 3 versions on Windows supply this function (natively supplied by Python 3.5 and above).

getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)[source]

Resolve host and port into list of address info entries.

Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. host is a domain name, a string representation of an IPv4/v6 address or None. port is a string service name such as ‘http’, a numeric port number or None. By passing None as the value of host and port, you can pass NULL to the underlying C API.

The family, type and proto arguments can be optionally specified in order to narrow the list of addresses returned. Passing zero as a value for each of these arguments selects the full range of results.

gethostbyname(host) → address[source]

Return the IP address (a string of the form ‘’) for a host.

gethostbyname_ex(host) -> (name, aliaslist, addresslist)[source]

Return the true host name, a list of aliases, and a list of IP addresses, for a host. The host argument is a string giving a host name or IP number. Resolve host and port into list of address info entries.

gethostbyaddr(ip_address) -> (name, aliaslist, addresslist)[source]

Return the true host name, a list of aliases, and a list of IP addresses, for a host. The host argument is a string giving a host name or IP number.

getnameinfo(sockaddr, flags) -> (host, port)[source]

Get host and port for a sockaddr.


Get fully qualified domain name from name.

An empty argument is interpreted as meaning the local host.

First the hostname returned by gethostbyaddr() is checked, then possibly existing aliases. In case no FQDN is available, hostname from gethostname() is returned.

Next page: gevent._socket2 – Python 2 socket module