Siddharth Sampath
Siddharth Sampath

Reputation: 145

Simultaneously generating threads

Is it possible to generate and run n number of threads at the same time? I want to run around 10000 threads for 5 seconds but I'm not able to achieve this as only a certain number of threads are able to get executed within the 5 seconds for which the program runs. A major number of the threads do not run. (Execution time of all the threads together should be 5 seconds)

Upvotes: 0

Views: 37

Answers (1)

Skam
Skam

Reputation: 7798

In short, no. You cannot run n threads simultaneously in Python. This is due to Python's Global Interpreter Lock, or GIL, as you may find online. Parallel execution of Python threads is not possible. Only one thread is allowed to access the interpreter at a time because of the GIL.

If you want to achieve such a behavior, try multiprocessing.

Upvotes: 1

Related Questions