Microthreads: wait( duration ) with minimal processor overhea d, u

Mike Fletcher mfletch at tpresence.com
Fri May 26 23:20:48 EDT 2000


The thing this modification allows is to "sleep" or "wait" a micro-thread
for a specified (real-time) duration without requiring an active thread
running constantly to unblock the client.  I've not seen anything else in
the micro-threads libraries that allows this.

class Timer(Blockable):
...
	def mythread(self):
		import time
		while time.clock() < self.finish:
			switchContext()
		self.notifyAll()

	def start(self):
		new(self.mythread)

Note that the Timer is actually creating a tight loop that gets a time-slice
on each pass through the thread list.  If you have 3000 Timers running,
you've got 3000 versions of this loop gobbling up processor power.  wait'ing
3000 (or however many) threads, in contrast, means you have 2 checks on each
loop through the active threads.  When all micro-threads are suspended, the
os thread gets suspended, so you drop to ~0 processing load.

In my app, using a 0.01s wait in a polling loop takes the processor load
from 100% to below 5%.

Regarding decoding mime files:

	import mimetools
	mimetools.decode( sourcefile, destfile, 'quoted-printable' )

Enjoy,
Mike

-----Original Message-----
From: wware at world.std.com [mailto:wware at world.std.com]
Sent: Friday, May 26, 2000 9:42 PM
To: python-list at python.org
Subject: Re: Microthreads: wait( duration ) with minimal processor
overhead, u


Mike Fletcher (mfletch at tpresence.com) wrote:
> Attached find uthread6.py (modified version of Just's uthread4.py).  This
> adds a mechanism for putting micro-threads to sleep (with minimal
processor
> overhead), both when other micro-threads are running and when only
sleeping
> threads are present.
> ... it should keep micro-threads from always pegging the processor in
> low-load conditions (such as watching ports).

Normal sleeping threads (for instance, a thread that has blocked while
waiting for input from a queue, or waiting for a timer to finish) do not
take up any processor activity until the they are reactivated by the
event that wakes them. I think you may be working on an already-solved
problem.

> [uthread6.py]

Using the Unix 'mail' program, I find that the text is full of nonsense
like "3D" and "=09". I think this is an artifact of MIME encoding. Is
there any way to repost it without this stuff? Or is there a filter
somewhere handy for getting rid of it?

-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com
-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list