💾 Archived View for tris.fyi › pydoc › asyncore captured on 2023-04-26 at 13:26:36. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-01-08)
-=-=-=-=-=-=-
Basic infrastructure for asynchronous socket service clients and servers. There are only two ways to have a program on a single processor do "more than one thing at a time". Multi-threaded programming is the simplest and most popular way to do it, but there is another very different technique, that lets you have nearly all the advantages of multi-threading, without actually using multiple threads. it's really only practical if your program is largely I/O bound. If your program is CPU bound, then pre-emptive scheduled threads are probably what you really need. Network servers are rarely CPU-bound, however. If your operating system supports the select() system call in its I/O library (and nearly all do), then you can use it to juggle multiple communication channels at once; doing other work while your I/O is taking place in the "background." Although this strategy can seem strange and complex, especially at first, it is in many ways easier to understand and control than multi-threaded programming. The module documented here solves many of the difficult problems for you, making the task of building sophisticated high-performance network servers and clients a snap.
with_traceback(...) Exception.with_traceback(tb) -- set self.__traceback__ to tb and return self.
args = <attribute 'args' of 'BaseException' objects>
accept(self)
add_channel(self, map=None)
bind(self, addr)
close(self)
connect(self, address)
create_socket(self, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>)
del_channel(self, map=None)
handle_accept(self)
handle_accepted(self, sock, addr)
handle_close(self)
handle_connect(self)
handle_connect_event(self)
handle_error(self)
handle_expt(self)
handle_expt_event(self)
handle_read(self)
handle_read_event(self)
handle_write(self)
handle_write_event(self)
listen(self, num)
log(self, message)
log_info(self, message, type='info')
readable(self)
recv(self, buffer_size)
send(self, data)
set_reuse_addr(self)
set_socket(self, sock, map=None)
writable(self)
accepting = False
addr = None
closing = False
connected = False
connecting = False
debug = False
ignore_log_types = frozenset({'warning'})
accept(self)
add_channel(self, map=None)
bind(self, addr)
close(self)
connect(self, address)
create_socket(self, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>)
del_channel(self, map=None)
handle_accept(self)
handle_accepted(self, sock, addr)
handle_close(self)
handle_connect(self)
handle_connect_event(self)
handle_error(self)
handle_expt(self)
handle_expt_event(self)
handle_read(self)
handle_read_event(self)
handle_write(self)
handle_write_event(self)
initiate_send(self)
listen(self, num)
log(self, message)
log_info(self, message, type='info')
readable(self)
recv(self, buffer_size)
send(self, data)
set_reuse_addr(self)
set_socket(self, sock, map=None)
writable(self)
accepting = False
addr = None
closing = False
connected = False
connecting = False
debug = False
ignore_log_types = frozenset({'warning'})
accept(self)
add_channel(self, map=None)
bind(self, addr)
close(self)
connect(self, address)
create_socket(self, family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>)
del_channel(self, map=None)
handle_accept(self)
handle_accepted(self, sock, addr)
handle_close(self)
handle_connect(self)
handle_connect_event(self)
handle_error(self)
handle_expt(self)
handle_expt_event(self)
handle_read(self)
handle_read_event(self)
handle_write(self)
handle_write_event(self)
listen(self, num)
log(self, message)
log_info(self, message, type='info')
readable(self)
recv(self, buffer_size)
send(self, data)
set_file(self, fd)
set_reuse_addr(self)
set_socket(self, sock, map=None)
writable(self)
accepting = False
addr = None
closing = False
connected = False
connecting = False
debug = False
ignore_log_types = frozenset({'warning'})
close(self)
fileno(self)
getsockopt(self, level, optname, buflen=None)
recv(self, *args)
recv(self, *args)
send(self, *args)
send(self, *args)
close_all(map=None, ignore_all=False)
compact_traceback()
loop(timeout=30.0, use_poll=False, map=None, count=None)
poll(timeout=0.0, map=None)
poll2(timeout=0.0, map=None)
poll2(timeout=0.0, map=None)
read(obj)
readwrite(obj, flags)
write(obj)
EAGAIN = 11
EALREADY = 114
EBADF = 9
ECONNABORTED = 103
ECONNRESET = 104
EINPROGRESS = 115
EINVAL = 22
EISCONN = 106
ENOTCONN = 107
EPIPE = 32
ESHUTDOWN = 108
EWOULDBLOCK = 11
errorcode = {19: 'ENODEV', 50: 'ENOCSI', 113: 'EHOSTUNREACH', 42: 'ENOMSG', 117: 'EUCLEAN', 45: 'EL2NSYNC', 51: 'EL2HLT', 61: 'ENODATA', 15: 'ENOTBLK', 38: 'ENOSYS', 32: 'EPIPE', 22: 'EINVAL', 75: 'EOVERFLOW', 68: 'EADV', 4: 'EINTR', 87: 'EUSERS', 39: 'ENOTEMPTY', 105: 'ENOBUFS', 71: 'EPROTO', 66: 'EREMOTE', 119: 'ENAVAIL', 10: 'ECHILD', 40: 'ELOOP', 18: 'EXDEV', 7: 'E2BIG', 3: 'ESRCH', 90: 'EMSGSIZE', 97: 'EAFNOSUPPORT', 53: 'EBADR', 112: 'EHOSTDOWN', 96: 'EPFNOSUPPORT', 92: 'ENOPROTOOPT', 16: 'EBUSY', 11: 'EAGAIN', 77: 'EBADFD', 73: 'EDOTDOT', 106: 'EISCONN', 55: 'ENOANO', 108: 'ESHUTDOWN', 44: 'ECHRNG', 80: 'ELIBBAD', 64: 'ENONET', 52: 'EBADE', 9: 'EBADF', 72: 'EMULTIHOP', 5: 'EIO', 49: 'EUNATCH', 91: 'EPROTOTYPE', 28: 'ENOSPC', 8: 'ENOEXEC', 114: 'EALREADY', 100: 'ENETDOWN', 118: 'ENOTNAM', 13: 'EACCES', 48: 'ELNRNG', 84: 'EILSEQ', 20: 'ENOTDIR', 76: 'ENOTUNIQ', 1: 'EPERM', 33: 'EDOM', 54: 'EXFULL', 111: 'ECONNREFUSED', 21: 'EISDIR', 93: 'EPROTONOSUPPORT', 30: 'EROFS', 99: 'EADDRNOTAVAIL', 43: 'EIDRM', 70: 'ECOMM', 69: 'ESRMNT', 121: 'EREMOTEIO', 47: 'EL3RST', 74: 'EBADMSG', 23: 'ENFILE', 82: 'ELIBMAX', 29: 'ESPIPE', 67: 'ENOLINK', 102: 'ENETRESET', 110: 'ETIMEDOUT', 2: 'ENOENT', 17: 'EEXIST', 122: 'EDQUOT', 60: 'ENOSTR', 57: 'EBADSLT', 56: 'EBADRQC', 79: 'ELIBACC', 14: 'EFAULT', 27: 'EFBIG', 35: 'EDEADLOCK', 107: 'ENOTCONN', 89: 'EDESTADDRREQ', 81: 'ELIBSCN', 37: 'ENOLCK', 120: 'EISNAM', 103: 'ECONNABORTED', 101: 'ENETUNREACH', 116: 'ESTALE', 63: 'ENOSR', 12: 'ENOMEM', 88: 'ENOTSOCK', 86: 'ESTRPIPE', 31: 'EMLINK', 34: 'ERANGE', 83: 'ELIBEXEC', 46: 'EL3HLT', 104: 'ECONNRESET', 98: 'EADDRINUSE', 95: 'ENOTSUP', 78: 'EREMCHG', 36: 'ENAMETOOLONG', 25: 'ENOTTY', 85: 'ERESTART', 94: 'ESOCKTNOSUPPORT', 62: 'ETIME', 59: 'EBFONT', 109: 'ETOOMANYREFS', 24: 'EMFILE', 26: 'ETXTBSY', 115: 'EINPROGRESS', 6: 'ENXIO', 65: 'ENOPKG', 123: 'ENOMEDIUM', 124: 'EMEDIUMTYPE', 125: 'ECANCELED', 126: 'ENOKEY', 127: 'EKEYEXPIRED', 128: 'EKEYREVOKED', 129: 'EKEYREJECTED', 130: 'EOWNERDEAD', 131: 'ENOTRECOVERABLE', 132: 'ERFKILL'}
socket_map = {}