18. Interprocess Communication and Networking
The modules described in this chapter provide mechanisms for different processes to communicate.
Some modules only work for two processes that are on the same machine, e.g.
signal and mmap. Other modules support networking protocols
that two or more processes can use to communicate across machines.
The list of modules described in this chapter is:
- 18.1.
socket— Low-level networking interface- 18.1.1. Socket families
- 18.1.2. Module contents
- 18.1.2.1. Exceptions
- 18.1.2.2. Constants
AF_UNIXAF_INETAF_INET6SOCK_STREAMSOCK_DGRAMSOCK_RAWSOCK_RDMSOCK_SEQPACKETSOCK_CLOEXECSOCK_NONBLOCKSOMAXCONNAF_CANPF_CANCAN_BCMCAN_RAW_FD_FRAMESAF_PACKETPF_PACKETAF_RDSPF_RDSSOL_RDSSIO_RCVALLSIO_KEEPALIVE_VALSSIO_LOOPBACK_FAST_PATHAF_ALGSOL_ALGAF_LINKhas_ipv6BDADDR_ANYBDADDR_LOCALHCI_FILTERHCI_TIME_STAMPHCI_DATA_DIR
- 18.1.2.3. Functions
- 18.1.2.3.1. Creating sockets
- 18.1.2.3.2. Other functions
getaddrinfo()getfqdn()gethostbyname()gethostbyname_ex()gethostname()gethostbyaddr()getnameinfo()getprotobyname()getservbyname()getservbyport()ntohl()ntohs()htonl()htons()inet_aton()inet_ntoa()inet_pton()inet_ntop()CMSG_LEN()CMSG_SPACE()getdefaulttimeout()setdefaulttimeout()sethostname()if_nameindex()if_nametoindex()if_indextoname()
- 18.1.3. Socket Objects
socket.accept()socket.bind()socket.close()socket.connect()socket.connect_ex()socket.detach()socket.dup()socket.fileno()socket.get_inheritable()socket.getpeername()socket.getsockname()socket.getsockopt()socket.gettimeout()socket.ioctl()socket.listen()socket.makefile()socket.recv()socket.recvfrom()socket.recvmsg()socket.recvmsg_into()socket.recvfrom_into()socket.recv_into()socket.send()socket.sendall()socket.sendto()socket.sendmsg()socket.sendmsg_afalg()socket.sendfile()socket.set_inheritable()socket.setblocking()socket.settimeout()socket.setsockopt()socket.setsockopt()socket.setsockopt()socket.shutdown()socket.share()socket.familysocket.typesocket.proto
- 18.1.4. Notes on socket timeouts
- 18.1.5. Example
- 18.2.
ssl— TLS/SSL wrapper for socket objects- 18.2.1. Functions, Constants, and Exceptions
SSLErrorSSLZeroReturnErrorSSLWantReadErrorSSLWantWriteErrorSSLSyscallErrorSSLEOFErrorCertificateError- 18.2.1.1. Socket creation
- 18.2.1.2. Context creation
- 18.2.1.3. Random generation
- 18.2.1.4. Certificate handling
- 18.2.1.5. Constants
CERT_NONECERT_OPTIONALCERT_REQUIREDVerifyModeVERIFY_DEFAULTVERIFY_CRL_CHECK_LEAFVERIFY_CRL_CHECK_CHAINVERIFY_X509_STRICTVERIFY_X509_TRUSTED_FIRSTVerifyFlagsPROTOCOL_TLSPROTOCOL_TLS_CLIENTPROTOCOL_TLS_SERVERPROTOCOL_SSLv23PROTOCOL_SSLv2PROTOCOL_SSLv3PROTOCOL_TLSv1PROTOCOL_TLSv1_1PROTOCOL_TLSv1_2OP_ALLOP_NO_SSLv2OP_NO_SSLv3OP_NO_TLSv1OP_NO_TLSv1_1OP_NO_TLSv1_2OP_NO_TLSv1_3OP_CIPHER_SERVER_PREFERENCEOP_SINGLE_DH_USEOP_SINGLE_ECDH_USEOP_ENABLE_MIDDLEBOX_COMPATOP_NO_COMPRESSIONOptionsOP_NO_TICKETHAS_ALPNHAS_ECDHHAS_SNIHAS_NPNHAS_TLSv1_3CHANNEL_BINDING_TYPESOPENSSL_VERSIONOPENSSL_VERSION_INFOOPENSSL_VERSION_NUMBERALERT_DESCRIPTION_HANDSHAKE_FAILUREALERT_DESCRIPTION_INTERNAL_ERRORAlertDescriptionPurpose.SERVER_AUTHPurpose.CLIENT_AUTHSSLErrorNumber
- 18.2.2. SSL Sockets
SSLSocketSSLSocket.read()SSLSocket.write()SSLSocket.do_handshake()SSLSocket.getpeercert()SSLSocket.cipher()SSLSocket.shared_ciphers()SSLSocket.compression()SSLSocket.get_channel_binding()SSLSocket.selected_alpn_protocol()SSLSocket.selected_npn_protocol()SSLSocket.unwrap()SSLSocket.verify_client_post_handshake()SSLSocket.version()SSLSocket.pending()SSLSocket.contextSSLSocket.server_sideSSLSocket.server_hostnameSSLSocket.sessionSSLSocket.session_reused
- 18.2.3. SSL Contexts
SSLContextSSLContext.cert_store_stats()SSLContext.load_cert_chain()SSLContext.load_default_certs()SSLContext.load_verify_locations()SSLContext.get_ca_certs()SSLContext.get_ciphers()SSLContext.set_default_verify_paths()SSLContext.set_ciphers()SSLContext.set_alpn_protocols()SSLContext.set_npn_protocols()SSLContext.set_servername_callback()SSLContext.load_dh_params()SSLContext.set_ecdh_curve()SSLContext.wrap_socket()SSLContext.wrap_bio()SSLContext.session_stats()SSLContext.check_hostnameSSLContext.optionsSSLContext.post_handshake_authSSLContext.protocolSSLContext.verify_flagsSSLContext.verify_mode
- 18.2.4. Certificates
- 18.2.5. Examples
- 18.2.6. Notes on non-blocking sockets
- 18.2.7. Memory BIO Support
- 18.2.8. SSL session
- 18.2.9. Security considerations
- 18.2.10. LibreSSL support
- 18.2.1. Functions, Constants, and Exceptions
- 18.3.
select— Waiting for I/O completion - 18.4.
selectors— High-level I/O multiplexing - 18.5.
asyncio— Asynchronous I/O, event loop, coroutines and tasks- 18.5.1. Base Event Loop
BaseEventLoopAbstractEventLoop- 18.5.1.1. Run an event loop
- 18.5.1.2. Calls
- 18.5.1.3. Delayed calls
- 18.5.1.4. Futures
- 18.5.1.5. Tasks
- 18.5.1.6. Creating connections
- 18.5.1.7. Creating listening connections
- 18.5.1.8. Watch file descriptors
- 18.5.1.9. Low-level socket operations
- 18.5.1.10. Resolve host name
- 18.5.1.11. Connect pipes
- 18.5.1.12. UNIX signals
- 18.5.1.13. Executor
- 18.5.1.14. Error Handling API
- 18.5.1.15. Debug mode
- 18.5.1.16. Server
- 18.5.1.17. Handle
- 18.5.1.18. Event loop examples
- 18.5.2. Event loops
- 18.5.3. Tasks and coroutines
- 18.5.4. Transports and protocols (callback based API)
- 18.5.4.1. Transports
- 18.5.4.2. Protocols
- 18.5.4.3. Protocol examples
- 18.5.5. Streams (coroutine based API)
- 18.5.6. Subprocess
- 18.5.6.1. Windows event loop
- 18.5.6.2. Create a subprocess: high-level API using Process
- 18.5.6.3. Create a subprocess: low-level API using subprocess.Popen
- 18.5.6.4. Constants
- 18.5.6.5. Process
asyncio.subprocess.Processasyncio.subprocess.Process.wait()asyncio.subprocess.Process.communicate()asyncio.subprocess.Process.send_signal()asyncio.subprocess.Process.terminate()asyncio.subprocess.Process.kill()asyncio.subprocess.Process.stdinasyncio.subprocess.Process.stdoutasyncio.subprocess.Process.stderrasyncio.subprocess.Process.pidasyncio.subprocess.Process.returncode
- 18.5.6.6. Subprocess and threads
- 18.5.6.7. Subprocess examples
- 18.5.7. Synchronization primitives
- 18.5.8. Queues
- 18.5.9. Develop with asyncio
- 18.5.9.1. Debug mode of asyncio
- 18.5.9.2. Cancellation
- 18.5.9.3. Concurrency and multithreading
- 18.5.9.4. Handle blocking functions correctly
- 18.5.9.5. Logging
- 18.5.9.6. Detect coroutine objects never scheduled
- 18.5.9.7. Detect exceptions never consumed
- 18.5.9.8. Chain coroutines correctly
- 18.5.9.9. Pending task destroyed
- 18.5.9.10. Close transports and event loops
- 18.5.1. Base Event Loop
- 18.6.
asyncore— Asynchronous socket handlerloop()dispatcherdispatcher.handle_read()dispatcher.handle_write()dispatcher.handle_expt()dispatcher.handle_connect()dispatcher.handle_close()dispatcher.handle_error()dispatcher.handle_accept()dispatcher.handle_accepted()dispatcher.readable()dispatcher.writable()dispatcher.create_socket()dispatcher.connect()dispatcher.send()dispatcher.recv()dispatcher.listen()dispatcher.bind()dispatcher.accept()dispatcher.close()
dispatcher_with_sendfile_dispatcherfile_wrapper- 18.6.1. asyncore Example basic HTTP client
- 18.6.2. asyncore Example basic echo server
- 18.7.
asynchat— Asynchronous socket command/response handler - 18.8.
signal— Set handlers for asynchronous events- 18.8.1. General rules
- 18.8.2. Module contents
SIG_DFLSIG_IGNCTRL_C_EVENTCTRL_BREAK_EVENTNSIGITIMER_REALITIMER_VIRTUALITIMER_PROFSIG_BLOCKSIG_UNBLOCKSIG_SETMASKItimerErroralarm()getsignal()pause()pthread_kill()pthread_sigmask()setitimer()getitimer()set_wakeup_fd()siginterrupt()signal()sigpending()sigwait()sigwaitinfo()sigtimedwait()
- 18.8.3. Example
- 18.9.
mmap— Memory-mapped file support
