Multithreading / multiprocess

T

tleeuwenburg

Is there anyway to begin a thread and execute a finite number of lines
of code, or a finite amount of time within it?

For example, say I create three child threads and I want to guarantee
equal timeshare between them, can I specify a quanta (say 400 LOC
although I know that is pretty small) to execute in each one in turn?

-T
 
D

Diez B. Roggisch

Is there anyway to begin a thread and execute a finite number of lines
of code, or a finite amount of time within it?

For example, say I create three child threads and I want to guarantee
equal timeshare between them, can I specify a quanta (say 400 LOC
although I know that is pretty small) to execute in each one in turn?

Not as such, no. You can play tricks with the trace-module, but these
ultimately fail when the code in question runs inside C - which puts a
stop to any python interpreter scheduling anyway, thus native threads
are used which can't be controlled on that level.


Diez
 
A

Aahz

Is there anyway to begin a thread and execute a finite number of lines
of code, or a finite amount of time within it?

For example, say I create three child threads and I want to guarantee
equal timeshare between them, can I specify a quanta (say 400 LOC
although I know that is pretty small) to execute in each one in turn?

You have extremely coarse-grained control with sys.setcheckinterval().
However, there is no guarantee which thread will pick up control after
each context switch, so one thread might get more than its share.
 
T

TennesseeLeeuwenburg

Not as such, no. You can play tricks with the trace-module, but these
ultimately fail when the code in question runs inside C - which puts a
stop to any python interpreter scheduling anyway, thus native threads
are used which can't be controlled on that level.

Diez

Mmmm good point. 1 line of Python != 1 line of C. That's probably not
very important for what I have in mind, but I hadn't really been
considering that angle.

Cheers,
-T
 
T

TennesseeLeeuwenburg

You have extremely coarse-grained control with sys.setcheckinterval().
However, there is no guarantee which thread will pick up control after
each context switch, so one thread might get more than its share.

Thanks for your reply! Will add that to my reading list.

Cheers,
-T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top