Merge lp:~exarkun/corotwine/standalone-greenlet into lp:corotwine

Proposed by Jean-Paul Calderone
Status: Merged
Approved by: Christopher Armstrong
Approved revision: 15
Merged at revision: 15
Proposed branch: lp:~exarkun/corotwine/standalone-greenlet
Merge into: lp:corotwine
Diff against target: 115 lines (+13/-12)
8 files modified
corotwine/__init__.py (+6/-0)
corotwine/clock.py (+1/-2)
corotwine/defer.py (+1/-2)
corotwine/examples.py (+1/-2)
corotwine/protocol.py (+1/-1)
corotwine/test_clock.py (+1/-2)
corotwine/test_defer.py (+1/-1)
corotwine/test_protocol.py (+1/-2)
To merge this branch: bzr merge lp:~exarkun/corotwine/standalone-greenlet
Reviewer Review Type Date Requested Status
Christopher Armstrong Approve
Review via email: mp+90133@code.launchpad.net

Commit message

Merge lp:~exarkun/corotwine/standalone-greenlet: Support the standalone 'greenlet' module in addition to the one from py.magic.

Author: exarkun
Reviewer: radix

This change adds a fallback to corotwine to use the "greenlet" library if "py.magic.greenlet" is unavailable. "py.magic.greenlet" appears no longer to be available in recent versions of pylib. The standalone "greenlet" module has the same API and appears to be the same code, split into an independent distribution. PyPy also supports the "greenlet" module (via its own implementation).

Description of the change

This change adds a fallback to corotwine to use the "greenlet" library if "py.magic.greenlet" is unavailable. "py.magic.greenlet" appears no longer to be available in recent versions of pylib. The standalone "greenlet" module has the same API and appears to be the same code, split into an independent distribution. PyPy also supports the "greenlet" module (via its own implementation).

I also centralized the logic for selecting which greenlet library to use, though I'm open to suggestions about better places to put that code.

To post a comment you must log in.
Revision history for this message
Christopher Armstrong (radix) wrote :

This looks good. Works on Ubuntu 12.04 with the "python-greenlet" package installed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'corotwine/__init__.py'
2--- corotwine/__init__.py 2008-03-29 21:46:57 +0000
3+++ corotwine/__init__.py 2012-01-25 15:29:25 +0000
4@@ -1,3 +1,9 @@
5 """
6 Corotwine, a coroutine-based API for Twisted.
7 """
8+
9+# Expose an alias for the greenlet package in use
10+try:
11+ from py.magic import greenlet
12+except ImportError:
13+ from greenlet import greenlet
14
15=== modified file 'corotwine/clock.py'
16--- corotwine/clock.py 2008-03-29 21:19:15 +0000
17+++ corotwine/clock.py 2012-01-25 15:29:25 +0000
18@@ -2,8 +2,7 @@
19 Time manipulation for greenlets.
20 """
21
22-from py.magic import greenlet
23-
24+from corotwine import greenlet
25 from corotwine.protocol import MAIN
26
27 def wait(seconds, clock=None):
28
29=== modified file 'corotwine/defer.py'
30--- corotwine/defer.py 2009-03-05 21:50:17 +0000
31+++ corotwine/defer.py 2012-01-25 15:29:25 +0000
32@@ -8,13 +8,12 @@
33 """
34
35 from corotwine.protocol import MAIN
36+from corotwine import greenlet
37
38 from twisted.python.failure import Failure
39 from twisted.python.util import mergeFunctionMetadata
40 from twisted.internet.defer import Deferred
41
42-from py.magic import greenlet
43-
44
45 def blockOn(d):
46 """
47
48=== modified file 'corotwine/examples.py'
49--- corotwine/examples.py 2008-03-31 02:27:55 +0000
50+++ corotwine/examples.py 2012-01-25 15:29:25 +0000
51@@ -10,8 +10,7 @@
52
53 from corotwine.protocol import gListenTCP, gConnectTCP, LineBuffer
54 from corotwine.defer import blockOn, deferredGreenlet
55-
56-from py.magic import greenlet
57+from corotwine import greenlet
58
59
60 def echo(transport):
61
62=== modified file 'corotwine/protocol.py'
63--- corotwine/protocol.py 2008-03-31 02:27:55 +0000
64+++ corotwine/protocol.py 2012-01-25 15:29:25 +0000
65@@ -12,7 +12,7 @@
66 from twisted.internet.error import ConnectionLost, ConnectionDone
67 from twisted.protocols.basic import LineReceiver
68
69-from py.magic import greenlet
70+from corotwine import greenlet
71
72
73 MAIN = greenlet.getcurrent()
74
75=== modified file 'corotwine/test_clock.py'
76--- corotwine/test_clock.py 2008-03-29 21:19:15 +0000
77+++ corotwine/test_clock.py 2012-01-25 15:29:25 +0000
78@@ -4,8 +4,7 @@
79 from twisted.trial.unittest import TestCase
80 from twisted.internet.task import Clock
81
82-from py.magic import greenlet
83-
84+from corotwine import greenlet
85 from corotwine.clock import wait
86
87
88
89=== modified file 'corotwine/test_defer.py'
90--- corotwine/test_defer.py 2008-03-29 21:19:15 +0000
91+++ corotwine/test_defer.py 2012-01-25 15:29:25 +0000
92@@ -1,8 +1,8 @@
93 """
94 Tests for L{corotwine.defer}.
95 """
96-from py.magic import greenlet
97
98+from corotwine import greenlet
99 from corotwine.defer import blockOn, deferredGreenlet
100 from corotwine.clock import wait
101
102
103=== modified file 'corotwine/test_protocol.py'
104--- corotwine/test_protocol.py 2008-03-31 02:20:47 +0000
105+++ corotwine/test_protocol.py 2012-01-25 15:29:25 +0000
106@@ -13,8 +13,7 @@
107
108 from corotwine.protocol import _GreenletFactory, LineBuffer, gConnectTCP
109 from corotwine.clock import wait
110-
111-from py.magic import greenlet
112+from corotwine import greenlet
113
114
115 class ServerTests(TestCase):

Subscribers

People subscribed via source and target branches

to all changes: