Limiting thread intruction count

Peter Hansen peter at engcorp.com
Sat Jul 7 10:51:31 EDT 2001


Neil Macneale wrote:
> 
> Is there a way to limit the number of instructions executed by a thread
> to a certain number?  

What do you mean by "instructions"?  Machine language opcodes?  Python
bytecode instructions?  Python source instructions ("statements")?

> 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.

Are you doing this to make the game "fair"?  In what sense?

Would you then need to consider the total amount of processing 
time used by a given thread?  Or are you trying to see how 
efficiently (in terms of source lines of code) your players can 
code their algorithms, by putting a limiter on their code
at a higher level such as source lines of code executed per
unit time?

By the way, Python can, depending on the platform, already 
do some kind of round-robin style of multithreading (switching
threads after a given number of Python bytecode instructions)
which may have an effect similar to what you are trying to 
achieve, but I suspect what you are really looking for can 
not be found in that way.

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list