diff --git a/AUTHORS b/AUTHORS index 1c5b981..264b35e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -25,7 +25,7 @@ Thanks To --------- * Brantley Harris, reporting bug #4 * Taso Du Val, reproing an exception squelching bug, saving children's lives ;-) -* R. Tyler Ballance, bug report on tpool on Windows +* R. Tyler Ballance, bug report on tpool on Windows, help with improving corolocal module * Sergey Shepelev, PEP 8 police :-) * Luci Stanescu, for reporting twisted hub bug * Marcus Cavanaugh, for test case code that has been incredibly useful in tracking down bugs diff --git a/eventlet/corolocal.py b/eventlet/corolocal.py index ab5dfb6..b90f544 100644 --- a/eventlet/corolocal.py +++ b/eventlet/corolocal.py @@ -5,24 +5,23 @@ def get_ident(): return id(api.getcurrent()) class local(object): - - def __init__(self): - self.__dict__['__objs'] = {} - - def __getattr__(self, attr, g=get_ident): + def __getattribute__(self, attr, g=get_ident): try: - return self.__dict__['__objs'][g()][attr] + d = object.__getattribute__(self, '__dict__') + return d.setdefault('__objs', {})[g()][attr] except KeyError: raise AttributeError( "No variable %s defined for the thread %s" % (attr, g())) def __setattr__(self, attr, value, g=get_ident): - self.__dict__['__objs'].setdefault(g(), {})[attr] = value + d = object.__getattribute__(self, '__dict__') + d.setdefault('__objs', {}).setdefault(g(), {})[attr] = value def __delattr__(self, attr, g=get_ident): try: - del self.__dict__['__objs'][g()][attr] + d = object.__getattribute__(self, '__dict__') + del d.setdefault('__objs', {})[g()][attr] except KeyError: raise AttributeError( "No variable %s defined for thread %s" diff --git a/eventlet/green/thread.py b/eventlet/green/thread.py index a08c818..449aaf3 100644 --- a/eventlet/green/thread.py +++ b/eventlet/green/thread.py @@ -15,12 +15,25 @@ def get_ident(gr=None): def start_new_thread(function, args=(), kwargs={}): g = spawn(function, *args, **kwargs) return get_ident(g) + +start_new = start_new_thread def allocate_lock(): return LockType(1) +allocate = allocate_lock + def exit(): raise greenlet.GreenletExit + +exit_thread = __thread.exit_thread + +def interrupt_main(): + curr = greenlet.getcurrent() + if curr.parent and not curr.parent.dead: + curr.parent.throw(KeyboardInterrupt()) + else: + raise KeyboardInterrupt() if hasattr(__thread, 'stack_size'): def stack_size(size=None): @@ -32,4 +45,4 @@ if hasattr(__thread, 'stack_size'): pass # not going to decrease stack_size, because otherwise other greenlets in this thread will suffer -# *TODO: 'exit_thread', 'interrupt_main', 'start_new', '_local', 'allocate' +from eventlet.corolocal import local as _local \ No newline at end of file diff --git a/eventlet/util.py b/eventlet/util.py index 674ecb7..ab6b5a2 100644 --- a/eventlet/util.py +++ b/eventlet/util.py @@ -181,32 +181,7 @@ def wrap_threading_local_with_coro_local(): identical to ``threadlocal.local`` """ from eventlet import api - def get_ident(): - return id(api.getcurrent()) - - class local(object): - def __init__(self): - self.__dict__['__objs'] = {} - - def __getattr__(self, attr, g=get_ident): - try: - return self.__dict__['__objs'][g()][attr] - except KeyError: - raise AttributeError( - "No variable %s defined for the thread %s" - % (attr, g())) - - def __setattr__(self, attr, value, g=get_ident): - self.__dict__['__objs'].setdefault(g(), {})[attr] = value - - def __delattr__(self, attr, g=get_ident): - try: - del self.__dict__['__objs'][g()][attr] - except KeyError: - raise AttributeError( - "No variable %s defined for thread %s" - % (attr, g())) - + from eventlet.corolocal import local threading.local = local diff --git a/tests/stdlib/all.py b/tests/stdlib/all.py index e6bc043..b1d7cfc 100644 --- a/tests/stdlib/all.py +++ b/tests/stdlib/all.py @@ -17,22 +17,41 @@ def import_main(g, name): modobj.test_main.__name__ = name + '.test_main' except AttributeError: print "No test_main for %s, assuming it tests on import" % name - + + +# quick and dirty way of testing whether we can access +# remote hosts; any tests that try internet connections +# will fail if we cannot +import socket +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +try: + s.settimeout(0.5) + s.connect(('eventlet.net', 80)) + s.close() + have_network_access = True +except socket.error, e: + have_network_access = False + + import_main(globals(), 'test_SimpleHTTPServer') import_main(globals(), 'test_asynchat') import_main(globals(), 'test_asyncore') import_main(globals(), 'test_ftplib') import_main(globals(), 'test_httplib') -#import_main(globals(), 'test_httpservers') +if have_network_access: + import_main(globals(), 'test_httpservers') import_main(globals(), 'test_select') -import_main(globals(), 'test_socket') -#import_main(globals(), 'test_socket_ssl') +if have_network_access: + import_main(globals(), 'test_socket') +import_main(globals(), 'test_socket_ssl') import_main(globals(), 'test_socketserver') #import_main(globals(), 'test_ssl') import_main(globals(), 'test_thread') -#import_main(globals(), 'test_threading') -#import_main(globals(), 'test_threading_local') -import_main(globals(), 'test_timeout') +import_main(globals(), 'test_threading') +import_main(globals(), 'test_threading_local') +if have_network_access: + import_main(globals(), 'test_timeout') import_main(globals(), 'test_urllib') -import_main(globals(), 'test_urllib2') +if have_network_access: + import_main(globals(), 'test_urllib2') import_main(globals(), 'test_urllib2_localnet') \ No newline at end of file diff --git a/tests/stdlib/test_socket_ssl.py b/tests/stdlib/test_socket_ssl.py index 55cea01..d7fb21d 100644 --- a/tests/stdlib/test_socket_ssl.py +++ b/tests/stdlib/test_socket_ssl.py @@ -5,6 +5,12 @@ from eventlet.green import socket from eventlet.green import urllib from eventlet.green import threading +try: + socket.ssl + socket.sslerror +except AttributeError: + raise ImportError("Socket module doesn't support ssl") + patcher.inject('test.test_socket_ssl', globals(), ('socket', socket),