Am Sat, Jun 15, 2024 at 04:07:28PM -0700 schrieb Mark Knecht:

>    Now, the fun part. I wrote you a little Python program which on
> my system is called Dales_Loop.py. This program has 3
> parameters - a value to count to, the number of cores to be used,
> and a timeout value to stop the program. Using a program like
> this can give you repeatable results.

FYI, there is a problem with your approach: python is not capable of true 
multiprocessing. While you can have multiple threads in your programm, in 
the end they are executed by a single thread in a time-sharing manner.

This problem is known as the GIL—the Global Interpreter Lock. Unless you use 
an external program to do the actual CPU work, i.e. let the linux kernel do 
the actual parallelism and not python, your program is not faster than doing 
everything in a single loop.

See this page for a nice example which does basically the same as your 
program (heading “The Impact on Multi-Threaded Python Programs”), including 
some comparative benchmarking between single loop and threaded loops:
https://realpython.com/python-gil/

-- 
Grüße | Greetings | Salut | Qapla’
Please do not share anything from, with or about me on any social network.

At night, when everybody sleeps, usually there’s nobody awake.

Attachment: signature.asc
Description: PGP signature

Reply via email to