简体   繁体   中英

Figuring out the max number of concurrent python scripts

Say I want to run:

python script1.py &
python script2.py &

Each script is the same and just processes different files. How can I figure out how many of these scripts can I split into ?

What is the relation to the CPU core count or number of threads ? (memory wise I can figure it out)

Whenever you execute python script.py & this will create a new process that will be running in background and performing the work specified in script.py .

You can basically start the maximum number of process as supported on your system, you can find out using executing the command cat /proc/sys/kernel/pid_max which will probably returns 32768 . This number represents the maximum unique process identifiers the system can allocate to the processes.


Relation between CPU cores and number of threads:

Threads don't exists independently on their own they resides within a bounding process (the process which creates the threads). Threads do have their own stack and registers. Modern computers can creates 1000's(of course software threads) of thread simultaneously. But generally speaking the number of parallel threads that can execute is limited to number of CPU cores available on the system. In case of the system that supports hyper-threading this number may be higher.

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