Limiting thread intruction count
-$Paul$- at verence.demon.co.uk
Sun Jul 8 11:04:20 EDT 2001
In article <3b46ddb2$0$332$8eec23a at newsreader.tycho.net>,
Neil Macneale <mac4-devnull at theory.org> wrote:
>Is there a way to limit the number of instructions executed by a thread
>to a certain number? I want to start several threads and give them all
>the same number of instructions to work, then have them all stop after
>they have reached that point. Then I would like to resume all of those
>threads again for another 'round' of instruction batches.
>The idea is that I have a game where people play there code against
>others, and I would like to have some granularity in the number of
>intructions each thread executes in a given time frame.
>I think this may be impossible, but any suggestions would be great!
Greg Stein has a Robot Wars implementation which does what you want by
playing with thread locks in a function which is a sys.settrace hook.
sys.settrace lets you specify a function to run after every line of code
(it's intended for people writing debuggers).
(Unfortunately it's not a complete implementation: it'd be a cool way
to help beginners learn Python, especially those with a limited
attention span :-)
----- Paul Wright ------| Oh, how horrible our sins look when they are
-paul.wright at pobox.com--| committed by someone else! -- Chuck Smith
More information about the Python-list