From 70e4dd89d6f8a943fa617374d57590de8bc4b630 Mon Sep 17 00:00:00 2001 From: donovan Date: Wed, 21 May 2008 09:51:03 -0700 Subject: [PATCH] Some tweaks I made while importing back into svn --- eventlet/api.py | 2 +- eventlet/httpc.py | 1 - eventlet/runloop.py | 227 --------------------------------------- eventlet/runloop_test.py | 157 --------------------------- setup.py | 9 +- 5 files changed, 2 insertions(+), 394 deletions(-) delete mode 100644 eventlet/runloop.py delete mode 100644 eventlet/runloop_test.py diff --git a/eventlet/api.py b/eventlet/api.py index 35fe6a4..0e9f98e 100644 --- a/eventlet/api.py +++ b/eventlet/api.py @@ -299,7 +299,7 @@ def get_default_hub(): pass import select - if 0:#hasattr(select, 'poll'): + if hasattr(select, 'poll'): import eventlet.hubs.poll return eventlet.hubs.poll else: diff --git a/eventlet/httpc.py b/eventlet/httpc.py index 5d15e5e..34497b4 100644 --- a/eventlet/httpc.py +++ b/eventlet/httpc.py @@ -500,7 +500,6 @@ class HttpSuite(object): raise klass(params) def _get_response_body(self, params, connection): - print "CONENCTO", connection if connection is None: connection = connect(params.url, params.use_proxy) connection.request(params.method, params.path, params.body, diff --git a/eventlet/runloop.py b/eventlet/runloop.py deleted file mode 100644 index 24d7d81..0000000 --- a/eventlet/runloop.py +++ /dev/null @@ -1,227 +0,0 @@ -"""\ -@file runloop.py -@author Bob Ippolito - -Defines the core eventlet runloop. The runloop keeps track of scheduled -events and observers which watch for specific portions of the runloop to -be executed. - -Copyright (c) 2005-2006, Bob Ippolito -Copyright (c) 2007, Linden Research, Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -""" - -import time -import bisect -import sys -import traceback - -import greenlet - -from eventlet.timer import Timer - - -class RunLoop(object): - SYSTEM_EXCEPTIONS = (KeyboardInterrupt, SystemExit) - - def __init__(self, wait=None, clock=None): - if clock is None: - clock = self.default_clock() - self.clock = clock - if wait is None: - wait = self.default_wait - self.wait = wait - self.stopping = False - self.running = False - self.timers = [] - self.timers_by_greenlet = {} - self.next_timers = [] - self.observers = {} - self.observer_modes = { - 'entry': [], - 'before_timers': [], - 'before_waiting': [], - 'after_waiting': [], - 'exit': [], - } - - def default_wait(self, time): - return None - - def default_clock(self): - return time.time - - def default_sleep(self): - return 60.0 - - def sleep_until(self): - t = self.timers - if not t: - return None - return t[0][0] - - def run(self): - """Run the runloop until abort is called. - """ - if self.running: - raise RuntimeError("Already running!") - try: - self.running = True - self.stopping = False - self.fire_observers('entry') - while not self.stopping: - self.prepare_timers() - self.fire_observers('before_timers') - self.fire_timers(self.clock()) - self.prepare_timers() - wakeup_when = self.sleep_until() - if wakeup_when is None: - sleep_time = self.default_sleep() - else: - sleep_time = wakeup_when - self.clock() - if sleep_time > 0: - self.fire_observers('before_waiting') - self.wait(sleep_time) - self.fire_observers('after_waiting') - else: - self.wait(0) - else: - del self.timers[:] - del self.next_timers[:] - self.fire_observers('exit') - finally: - self.running = False - self.stopping = False - - def abort(self): - """Stop the runloop. If run is executing, it will exit after completing - the next runloop iteration. - """ - if self.running: - self.stopping = True - - def add_observer(self, observer, *modes): - """Add an event observer to this runloop with the given modes. - Valid modes are: - entry: The runloop is being entered. - before_timers: Before the expired timers for this iteration are executed. - before_waiting: Before waiting for the calculated wait_time - where nothing will happen. - after_waiting: After waiting, immediately before starting the top of the - runloop again. - exit: The runloop is exiting. - - If no mode is passed or mode is all, the observer will be fired for every - event type. - """ - if not modes or modes == ('all',): - modes = tuple(self.observer_modes) - self.observers[observer] = modes - for mode in modes: - self.observer_modes[mode].append(observer) - - def remove_observer(self, observer): - """Remove a previously registered observer from all event types. - """ - for mode in self.observers.pop(observer, ()): - self.observer_modes[mode].remove(observer) - - def squelch_observer_exception(self, observer, exc_info): - traceback.print_exception(*exc_info) - print >>sys.stderr, "Removing observer: %r" % (observer,) - self.remove_observer(observer) - - def fire_observers(self, activity): - for observer in self.observer_modes[activity]: - try: - observer(self, activity) - except self.SYSTEM_EXCEPTIONS: - raise - except: - self.squelch_observer_exception(observer, sys.exc_info()) - - def squelch_timer_exception(self, timer, exc_info): - traceback.print_exception(*exc_info) - print >>sys.stderr, "Timer raised: %r" % (timer,) - - def _add_absolute_timer(self, when, info): - # the 0 placeholder makes it easy to bisect_right using (now, 1) - self.next_timers.append((when, 0, info)) - - def add_timer(self, timer): - scheduled_time = self.clock() + timer.seconds - self._add_absolute_timer(scheduled_time, timer) - current_greenlet = greenlet.getcurrent() - if current_greenlet not in self.timers_by_greenlet: - self.timers_by_greenlet[current_greenlet] = {} - self.timers_by_greenlet[current_greenlet][timer] = True - timer.greenlet = current_greenlet - return scheduled_time - - def prepare_timers(self): - ins = bisect.insort_right - t = self.timers - for item in self.next_timers: - ins(t, item) - del self.next_timers[:] - - def schedule_call(self, seconds, cb, *args, **kw): - """Schedule a callable to be called after 'seconds' seconds have - elapsed. - seconds: The number of seconds to wait. - cb: The callable to call after the given time. - *args: Arguments to pass to the callable when called. - **kw: Keyword arguments to pass to the callable when called. - """ - t = Timer(seconds, cb, *args, **kw) - self.add_timer(t) - return t - - def fire_timers(self, when): - t = self.timers - last = bisect.bisect_right(t, (when, 1)) - i = 0 - for i in xrange(last): - timer = t[i][2] - try: - try: - timer() - except self.SYSTEM_EXCEPTIONS: - raise - except: - self.squelch_timer_exception(timer, sys.exc_info()) - finally: - try: - del self.timers_by_greenlet[timer.greenlet][timer] - except KeyError: - pass - del t[:last] - - def cancel_timers(self, greenlet): - if greenlet not in self.timers_by_greenlet: - return - for timer in self.timers_by_greenlet[greenlet]: - if not timer.cancelled and timer.seconds: - ## If timer.seconds is 0, this isn't a timer, it's - ## actually eventlet's silly way of specifying whether - ## a coroutine is "ready to run" or not. - timer.cancel() - print 'Runloop cancelling left-over timer %s' % timer - del self.timers_by_greenlet[greenlet] - diff --git a/eventlet/runloop_test.py b/eventlet/runloop_test.py deleted file mode 100644 index 4827c32..0000000 --- a/eventlet/runloop_test.py +++ /dev/null @@ -1,157 +0,0 @@ -"""\ -@file runloop_test.py -@author Donovan Preston - -Copyright (c) 2006-2007, Linden Research, Inc. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -""" - -import sys -import time -import StringIO -import unittest - -from eventlet import runloop - - -class TestRunloop(unittest.TestCase): - mode = 'static' - def test_empty(self): - r = runloop.RunLoop() - r.schedule_call(0, r.abort) - r.run() - assert not r.running - - - def test_timer(self): - r = runloop.RunLoop() - r.schedule_call(0.125, r.abort) - start_time = time.time() - r.run() - assert time.time() - start_time >= 0.125 - assert not r.running - - def test_observer(self): - observed = [] - r = runloop.RunLoop() - r.add_observer(lambda runloop, activity: observed.append(activity)) - r.schedule_call(0, r.abort) - r.run() - assert observed == ['entry', 'before_timers', 'before_waiting', 'after_waiting', 'exit'] - assert not r.running - - - def test_remove_observer(self): - r = runloop.RunLoop() - - observed = [] - def observe(runloop, mode): - observed.append(mode) - r.remove_observer(observe) - - looped = [] - def run_loop_twice(runloop, mode): - if looped: - r.abort() - else: - looped.append(True) - - r.add_observer(observe, 'before_timers') - r.add_observer(run_loop_twice, 'after_waiting') - r.run() - assert len(observed) == 1 - assert not r.running - - def test_observer_exception(self): - r = runloop.RunLoop() - - observed = [] - def observe(runloop, mode): - observed.append(mode) - raise Exception("Squelch me please") - - looped = [] - def run_loop_twice(runloop, mode): - if looped: - r.abort() - else: - looped.append(True) - - saved = sys.stderr - sys.stderr = err = StringIO.StringIO() - - r.add_observer(observe, 'before_timers') - r.add_observer(run_loop_twice, 'after_waiting') - r.run() - - err.seek(0) - sys.stderr = saved - - assert len(observed) == 1 - assert err.read() - assert not r.running - - def test_timer_exception(self): - r = runloop.RunLoop() - - observed = [] - def timer(): - observed.append(True) - raise Exception("Squelch me please") - - looped = [] - def run_loop_twice(runloop, mode): - if looped: - r.abort() - else: - looped.append(True) - - saved = sys.stderr - sys.stderr = err = StringIO.StringIO() - - r.schedule_call(0, timer) - r.add_observer(run_loop_twice, 'after_waiting') - r.run() - - err.seek(0) - sys.stderr = saved - - assert len(observed) == 1 - assert err.read() - assert not r.running - - def test_timer_system_exception(self): - r = runloop.RunLoop() - def timer(): - raise SystemExit - - r.schedule_call(0, timer) - - caught = [] - try: - r.run() - except SystemExit: - caught.append(True) - - assert caught - assert not r.running - -if __name__ == '__main__': - unittest.main() - diff --git a/setup.py b/setup.py index 70e16d2..fdd7d7c 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -from setuptools import Extension, find_packages, setup +from setuptools import find_packages, setup setup( @@ -27,10 +27,3 @@ setup( "Intended Audience :: Developers", "Development Status :: 4 - Beta"] ) - - - -setup(name="sendmsg", - version="1.0", - ext_modules=[Extension("sendmsg", ["src/sendmsg.c"])]) -