简体   繁体   中英

Controlling Thread Execution Time in Python

Is it possible to control the proportional execution time of a thread in python. For example, I have three functions F1, F2 and F3 in my program. I am calling each function with using start_new_thread in python. I want F2 thread to execute 70 percent of time while F1 and F3 should share rest of 30 percent. Is there a way to explicitly control these timings.

You could create a scheduler using a priority queue and a time quantum. Not sure on the specifics for this in Python, but the concept is the same: create a Scheduler class that accepts a thread, add the thread to a priority queue with a given priority, then sleep the thread after a specified time quantum has elapsed. You can tailor the time quantum depending on the current threads priority.

This is similar to how an Operating System schedules process threads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM