Permalink
Browse files

Reorganize the namespaces

Get rid of some tests for old code
  • Loading branch information...
Alvaro
Alvaro committed Nov 19, 2012
1 parent 5cf82a0 commit c264828ac6dd57a3b8f7e257899cce41e456ccd6
View
@@ -27,49 +27,9 @@
# THE SOFTWARE.
#
-version_info = (0, 0, 1, "dev")
-__version__ = ".".join(map(str, version_info))
-
-try:
- from evy import greenthread
- from evy import greenpool
- from evy import queue
- from evy import timeout
- from evy import patcher
- from evy import convenience
- import greenlet
-
- sleep = greenthread.sleep
- spawn = greenthread.spawn
- spawn_n = greenthread.spawn_n
- spawn_after = greenthread.spawn_after
- kill = greenthread.kill
-
- Timeout = TimeoutError = timeout.Timeout
- with_timeout = timeout.with_timeout
-
- GreenPool = greenpool.GreenPool
- GreenPile = greenpool.GreenPile
- Queue = queue.Queue
+__import__('pkg_resources').declare_namespace(__name__)
- import_patched = patcher.import_patched
- monkey_patch = patcher.monkey_patch
- connect = convenience.connect
- listen = convenience.listen
- serve = convenience.serve
- StopServe = convenience.StopServe
- wrap_ssl = convenience.wrap_ssl
-
- getcurrent = greenlet.greenlet.getcurrent
-
-except ImportError, e:
- # This is to make Debian packaging easier, it ignores import
- # errors of greenlet so that the packager can still at least
- # access the version. Also this makes easy_install a little quieter
- if 'greenlet' not in str(e):
- # any other exception should be printed
- import traceback
-
- traceback.print_exc()
+version_info = (0, 0, 1, "dev")
+__version__ = ".".join(map(str, version_info))
View
@@ -1 +1,33 @@
-__author__ = 'alvaro'
+#
+# Evy - a concurrent networking library for Python
+#
+# Unless otherwise noted, the files in Evy are under the following MIT license:
+#
+# Copyright (c) 2012, Alvaro Saurin
+# Copyright (c) 2008-2010, Eventlet Contributors (see AUTHORS)
+# Copyright (c) 2007-2010, Linden Research, Inc.
+# Copyright (c) 2005-2006, Bob Ippolito
+#
+# 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__('pkg_resources').declare_namespace(__name__)
+
+
View
@@ -23,3 +23,52 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
+
+
+
+
+try:
+ from evy import version_info, __version__
+
+ from evy import greenthread
+ from evy import greenpool
+ from evy import queue
+ from evy import timeout
+ from evy import patcher
+ from evy import convenience
+ import greenlet
+
+ sleep = greenthread.sleep
+ spawn = greenthread.spawn
+ spawn_n = greenthread.spawn_n
+ spawn_after = greenthread.spawn_after
+ kill = greenthread.kill
+
+ Timeout = TimeoutError = timeout.Timeout
+ with_timeout = timeout.with_timeout
+
+ GreenPool = greenpool.GreenPool
+ GreenPile = greenpool.GreenPile
+
+ Queue = queue.Queue
+
+ import_patched = patcher.import_patched
+ monkey_patch = patcher.monkey_patch
+
+ connect = convenience.connect
+ listen = convenience.listen
+ serve = convenience.serve
+ StopServe = convenience.StopServe
+ wrap_ssl = convenience.wrap_ssl
+
+ getcurrent = greenlet.greenlet.getcurrent
+
+except ImportError, e:
+ # This is to make Debian packaging easier, it ignores import
+ # errors of greenlet so that the packager can still at least
+ # access the version. Also this makes easy_install a little quieter
+ if 'greenlet' not in str(e):
+ # any other exception should be printed
+ import traceback
+
+ traceback.print_exc()
@@ -1,2 +1,37 @@
+#
+# Evy - a concurrent networking library for Python
+#
+# Unless otherwise noted, the files in Evy are under the following MIT license:
+#
+# Copyright (c) 2012, Alvaro Saurin
+# Copyright (c) 2008-2010, Eventlet Contributors (see AUTHORS)
+# Copyright (c) 2007-2010, Linden Research, Inc.
+# Copyright (c) 2005-2006, Bob Ippolito
+#
+# 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__('pkg_resources').declare_namespace(__name__)
+
import rand, crypto, SSL, tsafe
-from version import __version__
+from version import __version__
+
View
@@ -1 +1,37 @@
-# this package contains modules from the standard library converted to use evy
+#
+# Evy - a concurrent networking library for Python
+#
+# Unless otherwise noted, the files in Evy are under the following MIT license:
+#
+# Copyright (c) 2012, Alvaro Saurin
+# Copyright (c) 2008-2010, Eventlet Contributors (see AUTHORS)
+# Copyright (c) 2007-2010, Linden Research, Inc.
+# Copyright (c) 2005-2006, Bob Ippolito
+#
+# 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.
+#
+
+
+
+"""
+This package contains modules from the standard library converted to use Evy
+"""
+
+
+__import__('pkg_resources').declare_namespace(__name__)
View
@@ -40,8 +40,12 @@
DEBUG = True
+
+
+
class GreenPool(object):
- """The GreenPool class is a pool of green threads.
+ """
+ The GreenPool class is a pool of green threads.
"""
def __init__ (self, size = 1000):
@@ -69,14 +73,16 @@ def running (self):
return len(self.coroutines_running)
def free (self):
- """ Returns the number of greenthreads available for use.
+ """
+ Returns the number of greenthreads available for use.
If zero or less, the next call to :meth:`spawn` or :meth:`spawn_n` will
block the calling greenthread until a slot becomes available."""
return self.sem.counter
def spawn (self, function, *args, **kwargs):
- """Run the *function* with its arguments in its own green thread.
+ """
+ Run the *function* with its arguments in its own green thread.
Returns the :class:`GreenThread <evy.greenthread.GreenThread>`
object that is running the function, which can be used to retrieve the
results.
@@ -201,7 +207,8 @@ def return_stop_iteration ():
class GreenPile(object):
- """GreenPile is an abstraction representing a bunch of I/O-related tasks.
+ """
+ GreenPile is an abstraction representing a bunch of I/O-related tasks.
Construct a GreenPile with an existing GreenPool object. The GreenPile will
then use that pool's concurrency as it processes its jobs. There can be
@@ -226,8 +233,10 @@ def __init__ (self, size_or_pool = 1000):
self.counter = 0
def spawn (self, func, *args, **kw):
- """Runs *func* in its own green thread, with the result available by
- iterating over the GreenPile object."""
+ """
+ Runs *func* in its own green thread, with the result available by
+ iterating over the GreenPile object.
+ """
self.used = True
self.counter += 1
try:
@@ -241,19 +250,25 @@ def __iter__ (self):
return self
def next (self):
- """Wait for the next result, suspending the current greenthread until it
- is available. Raises StopIteration when there are no more results."""
+ """
+ Wait for the next result, suspending the current greenthread until it
+ is available. Raises StopIteration when there are no more results.
+ """
if self.counter == 0 and self.used:
raise StopIteration()
try:
return self.waiters.get().wait()
finally:
self.counter -= 1
-# this is identical to GreenPile but it blocks on spawn if the results
-# aren't consumed, and it doesn't generate its own StopIteration exception,
-# instead relying on the spawning process to send one in when it's done
+
class GreenMap(GreenPile):
+ """
+ A GreenMap is identical to GreenPile but it blocks on spawn if the results
+ aren't consumed, and it doesn't generate its own StopIteration exception,
+ instead relying on the spawning process to send one in when it's done
+ """
+
def __init__ (self, size_or_pool):
super(GreenMap, self).__init__(size_or_pool)
self.waiters = queue.LightQueue(maxsize = self.pool.size)
View
@@ -27,6 +27,11 @@
# THE SOFTWARE.
#
+
+__import__('pkg_resources').declare_namespace(__name__)
+
+
+
from evy.support import greenlets as greenlet
from evy import patcher
View
@@ -27,7 +27,12 @@
# THE SOFTWARE.
#
-from evy import coros
+import greenlet
+from greenlet.greenlet import getcurrent
+
+from evy.greenpool import GreenPool
+from evy.greenthread import spawn
+from evy.queue import Queue
from evy.semaphore import Semaphore
import warnings
@@ -42,9 +47,9 @@ def __init__ (self, min_size = 0, max_size = 4, track_events = False):
raise ValueError('min_size cannot be bigger than max_size')
self.max_size = max_size
self.sem = Semaphore(max_size)
- self.procs = proc.RunningProcSet()
+ self.procs = GreenPool()
if track_events:
- self.results = coros.queue()
+ self.results = Queue()
else:
self.results = None
@@ -63,7 +68,7 @@ def resize (self, new_max_size):
@property
def current_size (self):
""" The number of coroutines that are currently executing jobs. """
- return len(self.procs)
+ return self.procs.running()
def free (self):
""" Returns the number of coroutines that are available for doing
@@ -84,8 +89,8 @@ def execute (self, func, *args, **kwargs):
"""
# if reentering an empty pool, don't try to wait on a coroutine freeing
# itself -- instead, just execute in the current coroutine
- if self.sem.locked() and api.getcurrent() in self.procs:
- p = proc.spawn(func, *args, **kwargs)
+ if self.sem.locked() and getcurrent() in self.procs:
+ p = spawn(func, *args, **kwargs)
try:
p.wait()
except:
@@ -158,7 +163,6 @@ def process_all (self, function, iterable):
coroutines, newly-launched plus any previously-submitted :meth:`execute()`
or :meth:`execute_async` calls, have completed.
- >>> from evy import coros
>>> pool = coros.CoroutinePool()
>>> def saw(x): print "I saw %s!" % x
...
@@ -215,9 +219,8 @@ def generate_results (self, function, iterable, qsize = None):
above is when the *iterable*, which may itself be a generator, produces
millions of items.)
- >>> from evy import coros
>>> import string
- >>> pool = coros.CoroutinePool(max_size=5)
+ >>> pool = CoroutinePool(max_size=5)
>>> pausers = [coros.Event() for x in xrange(2)]
>>> def longtask(evt, desc):
... print "%s woke up with %s" % (desc, evt.wait())
@@ -291,7 +294,7 @@ def generate_results (self, function, iterable, qsize = None):
# coroutine calls send(result). We slyly pass a queue rather than an
# event -- the same queue instance for all coroutines. This is why our
# queue interface intentionally resembles the event interface.
- q = coros.queue(max_size = qsize)
+ q = Queue(max_size = qsize)
# How many results have we yielded so far?
finished = 0
# This first loop is only until we've launched all the coroutines. Its
Oops, something went wrong.

0 comments on commit c264828

Please sign in to comment.