Modified:
/trunk/libraries/stacklesslib/README.txt
/trunk/libraries/stacklesslib/setup.py
/trunk/libraries/stacklesslib/stacklesslib/main.py
/trunk/libraries/stacklesslib/stacklesslib/monkeypatch.py
/trunk/libraries/stacklesslib/stacklesslib/replacements/socket.py
=======================================
--- /trunk/libraries/stacklesslib/README.txt Mon Dec 19 01:31:21 2011
+++ /trunk/libraries/stacklesslib/README.txt Wed Dec 21 19:46:54 2011
@@ -31,6 +31,14 @@
Changes
-------
+Version 1.0.4:
+
+ * Modified monkey-patching to by default run a tasklet to pump
+ the scheduler. The ideal goal is that a user just needs to install
+ the monkey-patching and a non-Stackless standard library dependent
+ module should be able to be run without further modifications.
+ * Removed duplicate sleep method.
+
Version 1.0.3:
* All previous versions had broken eggs. This was because the manifest
was not
=======================================
--- /trunk/libraries/stacklesslib/setup.py Mon Dec 19 01:31:21 2011
+++ /trunk/libraries/stacklesslib/setup.py Wed Dec 21 19:46:54 2011
@@ -3,7 +3,7 @@
setup(
name = "stacklesslib",
packages = ["stacklesslib", "stacklesslib.replacements"],
- version = "1.0.3",
+ version = "1.0.4",
description = "Standard Stackless Python supporting functionality",
author = "Richard Tew",
author_email = "richar...@gmail.com",
@@ -19,43 +19,5 @@
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
],
- long_description = """\
-stacklesslib
-============
-
-Stackless Python by itself only provides a basic set of functionality,
-allowing either cooperative or preemptive scheduling of microthreads
-within the same operating system thread. This framework provides the
-additional support that anyone developing an application using Stackless
-Python will end up eventually implementing.
-
-The most useful aspect is the monkey-patching support. Much of the
-code in the standard library does blocking operations, or perhaps
-is even written to make use of threads. If the monkey-patching is
-installed, then these blocking operations are converted to be
-"Stackless friendly". Threads will actually be tasklets. Operations
-that block the operating system thread (and therefore the Stackless
-scheduler) will be converted to simply block the tasklet that is
-standing in for the threads that would otherwise be used.
-
-Even if an application developer does not wish to make use of
-monkey-patching, they can still make use the framework provided
-so that they do not need to implement the standard supporting
-functionality themselves.
-
-Useful supporting functionality:
-
- * Concurrency-related primitives corresponding to those that the
- standard library threading module provides for real threads.
- * Ability to put tasklets to sleep for a set amount of time.
- * Ability to specify timeouts for blocking operations.
-
-Changes
--------
-
-Version 1.0.3:
-
- * All previous versions had broken eggs. This was because the manifest
was not
- correctly configured to recursively include the source directory.
- """
-)
+ long_description = open("README.txt").read()
+)
=======================================
--- /trunk/libraries/stacklesslib/stacklesslib/main.py Mon Dec 19 00:10:28
2011
+++ /trunk/libraries/stacklesslib/stacklesslib/main.py Wed Dec 21 19:46:54
2011
@@ -171,7 +171,11 @@
def run_tasklets(self, run_for=0):
""" Run tasklets for as long as necessary """
try:
- return stackless.run(run_for)
+ # Can only directly invoke the scheduler from the main tasklet.
+ if stackless.current is stackless.main:
+ return stackless.run(run_for)
+ else:
+ stackless.schedule()
except Exception:
self.handle_run_error(sys.exc_info())
@@ -190,7 +194,11 @@
def run(self):
while self.running:
self.pump()
-
+
+ def start(self):
+ t = stackless.tasklet(self.run)()
+ t.run()
+
def stop(self):
self.running = False
@@ -213,18 +221,6 @@
def interrupt_wait(self):
stacklessio.break_wait()
-
-# Perhaps this function should be elsewhere...
-def sleep(delay):
- """Sleep the current tasklet for a while"""
- c = stackless.channel()
- set_channel_pref(c)
- def wakeup():
- if c.balance:
- c.send(None)
- event_queue.push_after(wakeup, delay)
- c.receive()
-
event_queue = EventQueue()
# Disable preferred socket solution of stacklessio for now.
@@ -232,3 +228,5 @@
mainloop = SLIOMainLoop()
else:
mainloop = MainLoop()
+
+sleep = mainloop.sleep
=======================================
--- /trunk/libraries/stacklesslib/stacklesslib/monkeypatch.py Mon Dec 19
00:10:28 2011
+++ /trunk/libraries/stacklesslib/stacklesslib/monkeypatch.py Wed Dec 21
19:46:54 2011
@@ -14,8 +14,7 @@
-def patch_all():
-
+def patch_all(autonomous=True):
patch_misc()
patch_thread()
@@ -24,6 +23,9 @@
patch_select()
patch_socket()
+ if autonomous:
+ main.mainloop.start()
+
def patch_misc():
# Fudge time.sleep.
@@ -50,7 +52,7 @@
from stacklesslib.replacements import select
sys.modules["select"] = select
-def patch_socket(will_be_pumped=True):
+def patch_socket(autononous=True):
"""
Selectively choose to monkey-patch the 'socket' module.
@@ -67,7 +69,8 @@
from stacklesslib.replacements import socket
socket._sleep_func = main.sleep
socket._schedule_func = lambda: main.sleep(0)
- if will_be_pumped:
+ # If the user plans to pump themselves, disable auto-pumping.
+ if not autononous:
socket._manage_sockets_func = lambda: None
socket.install()
-
+
=======================================
--- /trunk/libraries/stacklesslib/stacklesslib/replacements/socket.py Mon
Dec 19 00:10:28 2011
+++ /trunk/libraries/stacklesslib/stacklesslib/replacements/socket.py Wed
Dec 21 19:46:54 2011
@@ -134,9 +134,10 @@
try:
while len(asyncore.socket_map):
# Check the sockets for activity.
- #print "POLL"
+ # print "POLL"
asyncore.poll(poll_interval)
# Yield to give other tasklets a chance to be scheduled.
+ # print "SCHED"
_schedule_func()
finally:
managerRunning = False