This commit is contained in:
Ryan Williams
2010-01-08 18:55:22 -08:00
11 changed files with 83 additions and 69 deletions

View File

@@ -99,7 +99,9 @@ easy_install eventlet
<h3><a href="">Links</a></h3> <h3><a href="">Links</a></h3>
<ul> <ul>
<li><a class="reference external" href="doc/">Documentation</a></li> <li><a class="reference external" href="doc/">Documentation</a></li>
<li><a class="reference external" href="https://lists.secondlife.com/pipermail/eventletdev/">Mailing list archives</a></li> <li><a class="reference external" href="https://lists.secondlife.com/pipermail/eventletdev/">Mailing List Archives</a></li>
<li><a class="reference external" href="http://eventlet.net/hudson/">Continuous Builds</a></li>
<li><a class="reference external" href="http://bitbucket.org/which_linden/eventlet/issues/new/">Bug Report Form</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -67,8 +67,22 @@ def set_nonblocking(fd):
try: try:
setblocking = fd.setblocking setblocking = fd.setblocking
except AttributeError: except AttributeError:
# This version of Python predates socket.setblocking() # fd has no setblocking() method. It could be that this version of
import fcntl # Python predates socket.setblocking(). In that case, we can still set
# the flag "by hand" on the underlying OS fileno using the fcntl
# module.
try:
import fcntl
except ImportError:
# Whoops, Windows has no fcntl module. This might not be a socket
# at all, but rather a file-like object with no setblocking()
# method. In particular, on Windows, pipes don't support
# non-blocking I/O and therefore don't have that method. Which
# means fcntl wouldn't help even if we could load it.
raise NotImplementedError("set_nonblocking() on a file object "
"with no setblocking() method "
"(Windows pipes don't support non-blocking I/O)")
# We managed to import fcntl.
fileno = fd.fileno() fileno = fd.fileno()
flags = fcntl.fcntl(fileno, fcntl.F_GETFL) flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
fcntl.fcntl(fileno, fcntl.F_SETFL, flags | os.O_NONBLOCK) fcntl.fcntl(fileno, fcntl.F_SETFL, flags | os.O_NONBLOCK)

View File

@@ -96,7 +96,8 @@ class Hub(BaseHub):
self.schedule_call_global(0, api.getcurrent().parent.throw, *self.signal_exc_info) self.schedule_call_global(0, api.getcurrent().parent.throw, *self.signal_exc_info)
self.signal_exc_info = None self.signal_exc_info = None
else: else:
traceback.print_exc() if not self.silent_timer_exceptions:
traceback.print_exc()
def abort(self): def abort(self):
self.schedule_call_global(0, self.greenlet.throw, api.GreenletExit) self.schedule_call_global(0, self.greenlet.throw, api.GreenletExit)

View File

@@ -1,4 +1,4 @@
from cPickle import dumps, loads import cPickle as Pickle
import os import os
import struct import struct
import sys import sys
@@ -106,8 +106,8 @@ def _read_response(id, attribute, input, cp):
try: try:
str = _read_lp_hunk(input) str = _read_lp_hunk(input)
_prnt(`str`) _prnt(`str`)
response = loads(str) response = Pickle.loads(str)
except (AttributeError, DeadProcess), e: except (AttributeError, DeadProcess, Pickle.UnpicklingError), e:
raise UnrecoverableError(e) raise UnrecoverableError(e)
_prnt("response: %s" % response) _prnt("response: %s" % response)
if response[0] == 'value': if response[0] == 'value':
@@ -130,7 +130,7 @@ def _write_lp_hunk(stream, hunk):
def _write_request(param, output): def _write_request(param, output):
_prnt("request: %s" % param) _prnt("request: %s" % param)
str = dumps(param) str = Pickle.dumps(param)
_write_lp_hunk(output, str) _write_lp_hunk(output, str)
def _is_local(attribute): def _is_local(attribute):
@@ -495,7 +495,7 @@ class Server(object):
_log("Exiting normally") _log("Exiting normally")
sys.exit(0) sys.exit(0)
request = loads(str_) request = Pickle.loads(str_)
_log("request: %s (%s)" % (request, self._objects)) _log("request: %s (%s)" % (request, self._objects))
req = request req = request
id = None id = None
@@ -558,7 +558,7 @@ class Server(object):
def respond(self, body): def respond(self, body):
_log("responding with: %s" % body) _log("responding with: %s" % body)
#_log("objects: %s" % self._objects) #_log("objects: %s" % self._objects)
s = dumps(body) s = Pickle.dumps(body)
_log(`s`) _log(`s`)
str_ = _write_lp_hunk(self._out, s) str_ = _write_lp_hunk(self._out, s)

View File

@@ -15,6 +15,7 @@
import os import os
import threading import threading
import sys
from Queue import Empty, Queue from Queue import Empty, Queue
@@ -22,7 +23,7 @@ from eventlet import api, coros, greenio
__all__ = ['execute', 'Proxy', 'killall'] __all__ = ['execute', 'Proxy', 'killall']
QUIET=False QUIET=True
_rfile = _wfile = None _rfile = _wfile = None
@@ -71,9 +72,7 @@ def tworker():
except SYS_EXCS: except SYS_EXCS:
raise raise
except Exception,exn: except Exception,exn:
import sys rv = sys.exc_info()
(a,b,tb) = sys.exc_info()
rv = (exn,a,b,tb)
_rspq.put((e,rv)) _rspq.put((e,rv))
meth = args = kwargs = e = rv = None meth = args = kwargs = e = rv = None
_signal_t2e() _signal_t2e()
@@ -81,13 +80,13 @@ def tworker():
def erecv(e): def erecv(e):
rv = e.wait() rv = e.wait()
if isinstance(rv,tuple) and len(rv) == 4 and isinstance(rv[0],Exception): if isinstance(rv,tuple) and len(rv) == 3 and isinstance(rv[1],Exception):
import traceback import traceback
(e,a,b,tb) = rv (c,e,tb) = rv
if not QUIET: if not QUIET:
traceback.print_exception(Exception,e,tb) traceback.print_exception(c,e,tb)
traceback.print_stack() traceback.print_stack()
raise e raise c,e,tb
return rv return rv

View File

@@ -69,7 +69,7 @@ except ImportError:
return connection return connection
socket_already_wrapped = False socket_already_wrapped = False
def wrap_socket_with_coroutine_socket(use_thread_pool=True): def wrap_socket_with_coroutine_socket(use_thread_pool=False):
global socket_already_wrapped global socket_already_wrapped
if socket_already_wrapped: if socket_already_wrapped:
return return

View File

@@ -210,12 +210,12 @@ class TestApi(TestCase):
state.append('finished') state.append('finished')
g = api.spawn(test) g = api.spawn(test)
api.sleep(DELAY/2) api.sleep(DELAY/2)
assert state == ['start'], state self.assertEquals(state, ['start'])
api.kill(g) api.kill(g)
# will not get there, unless switching is explicitly scheduled by kill # will not get there, unless switching is explicitly scheduled by kill
assert state == ['start', 'except'], state self.assertEquals(state,['start', 'except'])
api.sleep(DELAY) api.sleep(DELAY)
assert state == ['start', 'except', 'finished'], state self.assertEquals(state, ['start', 'except', 'finished'])
def test_nested_with_timeout(self): def test_nested_with_timeout(self):
def func(): def func():

View File

@@ -1,7 +1,8 @@
import os import os
import tempfile import shutil
import subprocess import subprocess
import sys import sys
import tempfile
from tests import LimitedTestCase from tests import LimitedTestCase
@@ -16,49 +17,42 @@ from eventlet.green import socket
from eventlet.green import urllib from eventlet.green import urllib
from eventlet import patcher from eventlet import patcher
print 'patcher', socket, urllib print 'patcher', socket, urllib
patcher.inject('%s', globals(), ('socket', socket), ('urllib', urllib)) patcher.inject('base', globals(), ('socket', socket), ('urllib', urllib))
del patcher del patcher
""" """
import_module_contents = """ import_module_contents = """
import %(mod)s import patching
import httplib import socket
print "importing", %(mod)s, httplib, %(mod)s.socket, %(mod)s.urllib print "importing", patching, socket, patching.socket, patching.urllib
""" """
class Patcher(LimitedTestCase): class Patcher(LimitedTestCase):
TEST_TIMEOUT=3 # starting processes is time-consuming TEST_TIMEOUT=3 # starting processes is time-consuming
def setUp(self): def setUp(self):
self._saved_syspath = sys.path self._saved_syspath = sys.path
self.tempfiles = [] self.tempdir = tempfile.mkdtemp('_patcher_test')
def tearDown(self): def tearDown(self):
sys.path = self._saved_syspath sys.path = self._saved_syspath
for tf in self.tempfiles: shutil.rmtree(self.tempdir)
os.remove(tf)
def write_to_tempfile(self, contents): def write_to_tempfile(self, name, contents):
fn, filename = tempfile.mkstemp('_patcher_test.py') filename = os.path.join(self.tempdir, name + '.py')
fd = os.fdopen(fn, 'w') fd = open(filename, "w")
fd.write(contents) fd.write(contents)
fd.close() fd.close()
self.tempfiles.append(filename)
return os.path.dirname(filename), os.path.basename(filename)
def test_patch_a_module(self): def test_patch_a_module(self):
base = self.write_to_tempfile(base_module_contents) self.write_to_tempfile("base", base_module_contents)
base_modname = os.path.splitext(base[1])[0] self.write_to_tempfile("patching", patching_module_contents)
patching = self.write_to_tempfile(patching_module_contents % base_modname) self.write_to_tempfile("importing", import_module_contents)
patching_modname = os.path.splitext(patching[1])[0]
importing = self.write_to_tempfile(
import_module_contents % dict(mod=patching_modname))
python_path = os.pathsep.join(sys.path) python_path = os.pathsep.join(sys.path + [self.tempdir])
python_path += os.pathsep.join((base[0], patching[0], importing[0]))
new_env = os.environ.copy() new_env = os.environ.copy()
new_env['PYTHONPATH'] = python_path new_env['PYTHONPATH'] = python_path
p = subprocess.Popen([sys.executable, p = subprocess.Popen([sys.executable,
os.path.join(importing[0], importing[1])], os.path.join(self.tempdir, "importing.py")],
stdout=subprocess.PIPE, env=new_env) stdout=subprocess.PIPE, env=new_env)
output = p.communicate() output = p.communicate()
lines = output[0].split("\n") lines = output[0].split("\n")

View File

@@ -32,7 +32,7 @@ class CoroutineCallingClass(object):
class TestSaranwrap(LimitedTestCase): class TestSaranwrap(LimitedTestCase):
TEST_TIMEOUT=3 TEST_TIMEOUT=8
def assert_server_exists(self, prox): def assert_server_exists(self, prox):
self.assert_(saranwrap.status(prox)) self.assert_(saranwrap.status(prox))
prox.foo = 0 prox.foo = 0

View File

@@ -1,19 +1,19 @@
""" Convenience module for running standard library tests with nose. The standard tests are not especially homogeneous, but they mostly expose a test_main method that does the work of selecting which tests to run based on what is supported by the platform. On its own, Nose would run all possible tests and many would fail; therefore we collect all of the test_main methods here in one module and Nose can run it. Hopefully in the future the standard tests get rewritten to be more self-contained. """ Convenience module for running standard library tests with nose. The standard tests are not especially homogeneous, but they mostly expose a test_main method that does the work of selecting which tests to run based on what is supported by the platform. On its own, Nose would run all possible tests and many would fail; therefore we collect all of the test_main methods here in one module and Nose can run it. Hopefully in the future the standard tests get rewritten to be more nosey.
Many of these tests make connections to external servers, causing failures when run while disconnected from the internet. Many of these tests make connections to external servers, and all.py tries to skip these tests rather than failing them, so you can get some work done on a plane.
""" """
def import_main(g, name): def import_main(name):
try: try:
modobj = __import__(name, g, fromlist=['test_main']) modobj = __import__(name, globals(), locals(), ['test_main'])
except ImportError: except ImportError:
print "Not importing %s, it doesn't exist in this installation/version of Python" % name print "Not importing %s, it doesn't exist in this installation/version of Python" % name
return return
else: else:
method_name = name + "_test_main" method_name = name + "_test_main"
try: try:
g[method_name] = modobj.test_main globals()[method_name] = modobj.test_main
modobj.test_main.__name__ = name + '.test_main' modobj.test_main.__name__ = name + '.test_main'
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
@@ -33,26 +33,26 @@ except socket.error, e:
print "Skipping network tests" print "Skipping network tests"
have_network_access = False have_network_access = False
import_main(globals(), 'test_select') import_main('test_select')
import_main(globals(), 'test_SimpleHTTPServer') import_main('test_SimpleHTTPServer')
import_main(globals(), 'test_asynchat') import_main('test_asynchat')
import_main(globals(), 'test_asyncore') import_main('test_asyncore')
import_main(globals(), 'test_ftplib') import_main('test_ftplib')
import_main(globals(), 'test_httplib') import_main('test_httplib')
if have_network_access: if have_network_access:
import_main(globals(), 'test_httpservers') import_main('test_httpservers')
if have_network_access: if have_network_access:
import_main(globals(), 'test_socket') import_main('test_socket')
import_main(globals(), 'test_socket_ssl') import_main('test_socket_ssl')
import_main(globals(), 'test_socketserver') import_main('test_socketserver')
if have_network_access: if have_network_access:
import_main(globals(), 'test_ssl') import_main('test_ssl')
import_main(globals(), 'test_thread') import_main('test_thread')
import_main(globals(), 'test_threading') #import_main('test_threading')
import_main(globals(), 'test_threading_local') import_main('test_threading_local')
if have_network_access: if have_network_access:
import_main(globals(), 'test_timeout') import_main('test_timeout')
import_main(globals(), 'test_urllib') import_main('test_urllib')
if have_network_access: if have_network_access:
import_main(globals(), 'test_urllib2') import_main('test_urllib2')
import_main(globals(), 'test_urllib2_localnet') import_main('test_urllib2_localnet')

View File

@@ -8,6 +8,10 @@ patcher.inject('test.test_urllib2',
('urllib2', urllib2)) ('urllib2', urllib2))
HandlerTests.test_file = patcher.patch_function(HandlerTests.test_file, ('socket', socket)) HandlerTests.test_file = patcher.patch_function(HandlerTests.test_file, ('socket', socket))
try:
OpenerDirectorTests.test_badly_named_methods = patcher.patch_function(OpenerDirectorTests.test_badly_named_methods, ('urllib2', urllib2))
except AttributeError:
pass # 2.4 doesn't have this test method
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()