简体   繁体   English

在Python中管理多个线程

[英]Manage Multiple Threads in Python

Function gen() generates a string, which is a command to be passed into os.system(). 函数gen()生成一个字符串,该字符串是要传递给os.system()的命令。

I need to start 20 threads at the same time, call gen() for each thread, and run the command gen() gives me in each thread. 我需要同时启动20个线程,为每个线程调用gen(),然后在每个线程中运行gen()给我命令。 (parallel) (平行)

Once a command finishes executing in a thread, I want to call gen() again to generate another command, and run that command in the same thread. 一旦命令在线程中执行完毕,我想再次调用gen()来生成另一个命令,并在同一线程中运行该命令。

I want to to keep doing this until 10 minutes have passed. 我想继续这样做直到10分钟为止。

How do I do this? 我该怎么做呢?

Take a look at this , hope this helps. 看看这个 ,希望这有助于。

Its actually not that hard 实际上并不难

but keep in mind when working with threads which use the same variable to use locks ! 但是在使用使用相同变量来使用锁的线程时要记住!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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