From afc2068a98b5fe6eb367822d264b9e69b4dc37e0 Mon Sep 17 00:00:00 2001 From: rdw Date: Tue, 18 Mar 2008 17:32:07 -0500 Subject: [PATCH] Some Hub documentation, made wrap_socket_with_coroutine_socket happen only once. --- eventlet/hubs/hub.py | 17 +++++++++++++++++ eventlet/util.py | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/eventlet/hubs/hub.py b/eventlet/hubs/hub.py index ada6af7..a02104f 100644 --- a/eventlet/hubs/hub.py +++ b/eventlet/hubs/hub.py @@ -34,6 +34,9 @@ from eventlet import greenlib from eventlet.timer import Timer class BaseHub(object): + """ Base hub class for easing the implementation of subclasses that are + specific to a particular underlying event architecture. """ + SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit) def __init__(self, clock=time.time): @@ -58,6 +61,20 @@ class BaseHub(object): } def add_descriptor(self, fileno, read=None, write=None, exc=None): + """ Signals an intent to read/write from a particular file descriptor. + + The fileno argument is the file number of the file of interest. The other + arguments are either callbacks or None. If there is a callback for read + or write, the hub sets things up so that when the file descriptor is + ready to be read or written, the callback is called. + + The exc callback is called when the socket represented by the file + descriptor is closed. The intent is that the the exc callbacks should + only be present when either a read or write callback is also present, + so the exc callback happens instead of the respective read or write + callback. + """ + self.readers[fileno] = read or self.readers.get(fileno) self.writers[fileno] = write or self.writers.get(fileno) self.excs[fileno] = exc or self.excs.get(fileno) diff --git a/eventlet/util.py b/eventlet/util.py index 994ff4c..237aa95 100644 --- a/eventlet/util.py +++ b/eventlet/util.py @@ -90,8 +90,12 @@ def wrap_ssl(sock, certificate=None, private_key=None): connection.set_connect_state() return greenio.GreenSocket(connection) - +socket_already_wrapped = False def wrap_socket_with_coroutine_socket(): + global socket_already_wrapped + if socket_already_wrapped: + return + def new_socket(*args, **kw): from eventlet import greenio s = __original_socket__(*args, **kw) @@ -100,6 +104,8 @@ def wrap_socket_with_coroutine_socket(): socket.socket = new_socket socket.ssl = wrap_ssl + + socket_already_wrapped = True def socket_bind_and_listen(descriptor, addr=('', 0), backlog=50):