On 2006-08-09, Tim Chase <[EMAIL PROTECTED]> wrote: >> Problem is that I would have to share the CPU between all the robots, >> and thus allocate a time period to each robot. However I couldn't find >> any way to start a thread (robot), and interrupt it after a given time >> period. >> Any suggestions on how to proceed?
> >>> import thread, time > >>> def robot(name): > ... for i in xrange(5): > ... print "%s on pass %i" % (name, i) > ... time.sleep(0.01) >[...] I originally suggested the thread/sleep() scheme, but after thinking about it more, I really like the generator approach in the case where you want to explicity end each robot's "turn" using the CPU (which is what the sleep() call does). OTOH, if you want the robots to wait for events of some sort (e.g. from a queue) or data from an I/O device, then threading is probably the way to go. I guess it all depends on whether the robots' behavior is to be time-driven or event-driven. -- Grant Edwards grante Yow! Used staples are good at with SOY SAUCE! visi.com -- http://mail.python.org/mailman/listinfo/python-list