Fleshed out the rest of eventlet.green.thread, tweaked all.py so it discerns which tests will run when the frikkin internet is down, and used the improved corolocal that Tyler and I worked on (and fixed some bugs with it that these tests revealed.
This commit is contained in:
2
AUTHORS
2
AUTHORS
@@ -25,7 +25,7 @@ Thanks To
|
|||||||
---------
|
---------
|
||||||
* Brantley Harris, reporting bug #4
|
* Brantley Harris, reporting bug #4
|
||||||
* Taso Du Val, reproing an exception squelching bug, saving children's lives ;-)
|
* 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 :-)
|
* Sergey Shepelev, PEP 8 police :-)
|
||||||
* Luci Stanescu, for reporting twisted hub bug
|
* Luci Stanescu, for reporting twisted hub bug
|
||||||
* Marcus Cavanaugh, for test case code that has been incredibly useful in tracking down bugs
|
* Marcus Cavanaugh, for test case code that has been incredibly useful in tracking down bugs
|
||||||
|
@@ -5,24 +5,23 @@ def get_ident():
|
|||||||
return id(api.getcurrent())
|
return id(api.getcurrent())
|
||||||
|
|
||||||
class local(object):
|
class local(object):
|
||||||
|
def __getattribute__(self, attr, g=get_ident):
|
||||||
def __init__(self):
|
|
||||||
self.__dict__['__objs'] = {}
|
|
||||||
|
|
||||||
def __getattr__(self, attr, g=get_ident):
|
|
||||||
try:
|
try:
|
||||||
return self.__dict__['__objs'][g()][attr]
|
d = object.__getattribute__(self, '__dict__')
|
||||||
|
return d.setdefault('__objs', {})[g()][attr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
"No variable %s defined for the thread %s"
|
"No variable %s defined for the thread %s"
|
||||||
% (attr, g()))
|
% (attr, g()))
|
||||||
|
|
||||||
def __setattr__(self, attr, value, g=get_ident):
|
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):
|
def __delattr__(self, attr, g=get_ident):
|
||||||
try:
|
try:
|
||||||
del self.__dict__['__objs'][g()][attr]
|
d = object.__getattribute__(self, '__dict__')
|
||||||
|
del d.setdefault('__objs', {})[g()][attr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
"No variable %s defined for thread %s"
|
"No variable %s defined for thread %s"
|
||||||
|
@@ -16,12 +16,25 @@ def start_new_thread(function, args=(), kwargs={}):
|
|||||||
g = spawn(function, *args, **kwargs)
|
g = spawn(function, *args, **kwargs)
|
||||||
return get_ident(g)
|
return get_ident(g)
|
||||||
|
|
||||||
|
start_new = start_new_thread
|
||||||
|
|
||||||
def allocate_lock():
|
def allocate_lock():
|
||||||
return LockType(1)
|
return LockType(1)
|
||||||
|
|
||||||
|
allocate = allocate_lock
|
||||||
|
|
||||||
def exit():
|
def exit():
|
||||||
raise greenlet.GreenletExit
|
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'):
|
if hasattr(__thread, 'stack_size'):
|
||||||
def stack_size(size=None):
|
def stack_size(size=None):
|
||||||
if size is None:
|
if size is None:
|
||||||
@@ -32,4 +45,4 @@ if hasattr(__thread, 'stack_size'):
|
|||||||
pass
|
pass
|
||||||
# not going to decrease stack_size, because otherwise other greenlets in this thread will suffer
|
# 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
|
@@ -181,32 +181,7 @@ def wrap_threading_local_with_coro_local():
|
|||||||
identical to ``threadlocal.local``
|
identical to ``threadlocal.local``
|
||||||
"""
|
"""
|
||||||
from eventlet import api
|
from eventlet import api
|
||||||
def get_ident():
|
from eventlet.corolocal import local
|
||||||
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()))
|
|
||||||
|
|
||||||
threading.local = local
|
threading.local = local
|
||||||
|
|
||||||
|
|
||||||
|
@@ -18,21 +18,40 @@ def import_main(g, name):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
print "No test_main for %s, assuming it tests on import" % name
|
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_SimpleHTTPServer')
|
||||||
import_main(globals(), 'test_asynchat')
|
import_main(globals(), 'test_asynchat')
|
||||||
import_main(globals(), 'test_asyncore')
|
import_main(globals(), 'test_asyncore')
|
||||||
import_main(globals(), 'test_ftplib')
|
import_main(globals(), 'test_ftplib')
|
||||||
import_main(globals(), 'test_httplib')
|
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_select')
|
||||||
import_main(globals(), 'test_socket')
|
if have_network_access:
|
||||||
#import_main(globals(), 'test_socket_ssl')
|
import_main(globals(), 'test_socket')
|
||||||
|
import_main(globals(), 'test_socket_ssl')
|
||||||
import_main(globals(), 'test_socketserver')
|
import_main(globals(), 'test_socketserver')
|
||||||
#import_main(globals(), 'test_ssl')
|
#import_main(globals(), 'test_ssl')
|
||||||
import_main(globals(), 'test_thread')
|
import_main(globals(), 'test_thread')
|
||||||
#import_main(globals(), 'test_threading')
|
import_main(globals(), 'test_threading')
|
||||||
#import_main(globals(), 'test_threading_local')
|
import_main(globals(), 'test_threading_local')
|
||||||
import_main(globals(), 'test_timeout')
|
if have_network_access:
|
||||||
|
import_main(globals(), 'test_timeout')
|
||||||
import_main(globals(), 'test_urllib')
|
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')
|
import_main(globals(), 'test_urllib2_localnet')
|
@@ -5,6 +5,12 @@ from eventlet.green import socket
|
|||||||
from eventlet.green import urllib
|
from eventlet.green import urllib
|
||||||
from eventlet.green import threading
|
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',
|
patcher.inject('test.test_socket_ssl',
|
||||||
globals(),
|
globals(),
|
||||||
('socket', socket),
|
('socket', socket),
|
||||||
|
Reference in New Issue
Block a user