Python share CPU time?
Grant Edwards
grante at visi.com
Wed Aug 9 14:21:20 EDT 2006
On 2006-08-09, Yannick <yannick.leteigner at gmail.com> wrote:
> Hi,
>
> I would like to program a small game in Python, kind of like robocode
> (http://robocode.sourceforge.net/).
> 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.
The robot code thread needs to block when it runs out of things
to do.
> Any suggestions on how to proceed?
Just start a thread for each robot, and put a call to
time.sleep(0.010) in the main loop for the robot code. Adjust
the 0.010 value to taste.
As an alternative to sleeping, you could wait for some sort of
event each time through the loop.
> Is Python just not adapted to this kind of things?
It's quite well adapted to this sort of thing.
--
Grant Edwards grante Yow! Why don't you
at ever enter and CONTESTS,
visi.com Marvin?? Don't you know
your own ZIPCODE?
More information about the Python-list
mailing list