Micro-Threads: uthreadsleep.py -- scheduling of uthreads to conti nue processing after given seconds

Mike Fletcher mfletch at tpresence.com
Wed May 24 02:47:19 CEST 2000

While playing with making a uthreads-based server, I have found the lack of
a real-world-time sleeping function somewhat disconcerting (relying on
number of time slices when the system could vary from a cycle per
millisecond through a cycle every 10 seconds (on very heavily loaded
simulations) isn't very useful).

Accordingly, I created a module which provides for "sleeping" uthreads.
Unfortunately, because you cannot properly "suspend" a uthread (i.e. declare
that it is inactive until time x), there is no noticeable processor load
reduction when you have only waiting threads :( .  This is a demo, not a
production piece of code.  It is released into the public domain for
whatever it's worth.

To do processor load reduction, you would likely need to have a far more
involved run mechanism.  It should be possible to do something such as, on
the first cycle where there is no non-waiting thread, use time.sleep() to
wait until the first waiting thread should be restarted.  This would seem to
work with the current micro-threads philosophy (i.e. a single python thread
running all the micro-threads), as you would be able to declare that there
is no further work to do in the python thread until the timer wakes up.  In
a multi-threaded scenario, that could not be guaranteed (unless you force
the issue by preventing threads from adding to other thread's micro-thread
collection)?  The ability to use almost no processing power when not active
is somewhat of a requirement for many systems.

Incidentally, continuations/uthreads is, without a doubt, one of the coolest
things in Pythonica :) .  One question, why does the micro-threads library
use non-thread-safe mechanisms (global lists etc.)?  It limits the use of
the micro-threads to a single python thread.

Enjoy yourselves,

 Mike C. Fletcher
 Designer, VR Plumber

-------------- next part --------------
A non-text attachment was scrubbed...
Name: uthreadsleep.py
Type: application/octet-stream
Size: 1801 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20000523/e55727f8/attachment.obj>

More information about the Python-list mailing list