+ 4
Is it a good idea to use multi-thread to speed our Python code?
4 ответов
+ 2
Multiprocesses if CPU is the bottleneck
Multithread if i/o is bottleneck.
For CPU bottlenecks multithreading will be useless.
Read more about this in Google
tags=python gil
https://realpython.com/python-gil/
+ 1
There is potential to get a speed increase if the threads get executed in parallel across multiple CPU cores or if hyperthreading is supported in the CPU.
Also multithreading can improve speed if a thread performs i/o and gets blocked while waiting for the i/o device. At that point another thread may be given execution time while the blocked thread is waiting.
0
So, in principle, if you want multi-threaded code to speed up computations, it won't speed it up since only one thread is executing at a time, but if you use it, for example, to interact with a database, it will work.
0
This code has some scanning methods both with and without threads. The threaded methods work at least 3 times faster than the non threaded. if you want to test, just add a reference to a nonthreaded method in the command dictionary.
https://code.sololearn.com/ce1VUemhhYwS/?ref=app