Mar-01-2023, 02:00 AM
On a computer with only (1 CPU), how many threads can I run at the same time in the python process ?
Thread Limits . . .
|
Mar-01-2023, 02:00 AM
On a computer with only (1 CPU), how many threads can I run at the same time in the python process ?
Mar-01-2023, 02:12 AM
Threads have nothing to do with cpus
Mar-01-2023, 04:42 AM
Mar-01-2023, 07:47 AM
In pure python, you can have multiple threads active at one time, but only 1 will be running at any one time (regardless of how many cpus you have).
Mar-01-2023, 01:09 PM
The concept to understand is the GIL. Here is an article that explains what the GIL is, why multiple threads may exist and yet only one executes at a time, etc.
It comes down to that Python uses reference counting for variables rather than garbage collection.
Mar-01-2023, 01:17 PM
(Mar-01-2023, 01:09 PM)jefsummers Wrote: The concept to understand is the GIL. Here is an article that explains what the GIL is, why multiple threads may exist and yet only one executes at a time, etc. And if I use Cython, to program simultaneous multithreading, will I be able to escape the GIL?
Mar-01-2023, 09:49 PM
You likely won't see any problems that are related to the global interpreter lock. I've done quite a bit of programming involving muliple threads talking to different processes (IO intensive) and have never had a problem that I think is related to GIL.
What are you using threads for that makes you think you'll have huge numbers of threads.
Mar-01-2023, 11:16 PM
(This post was last modified: Mar-01-2023, 11:16 PM by JohnnyCoffee.)
(Mar-01-2023, 09:49 PM)deanhystad Wrote: You likely won't see any problems that are related to the global interpreter lock. I've done quite a bit of programming involving muliple threads talking to different processes (IO intensive) and have never had a problem that I think is related to GIL. I'm developing a very performant http web server.
Mar-02-2023, 12:57 PM
In Cython you can release the GIL, but given the application (will be IO intensive rather than CPU intensive) I would agree with @deanhystad that the GIL is unlikely to get in your way. And, releasing the GIL means you have to do the GIL's work. There is no free lunch.
IMHO, your bottlenecks will be getting info from your long term storage and placing that info on the network, not CPU processing. Threads will be "happy" to yield the processor while waiting for those things to happen. I don't know the details, but a quick Google search tells me that the following popular sites are done in Python: Youtube Spotify and the list goes on
Mar-02-2023, 04:44 PM
(Mar-02-2023, 12:57 PM)jefsummers Wrote: In Cython you can release the GIL, but given the application (will be IO intensive rather than CPU intensive) I would agree with @deanhystad that the GIL is unlikely to get in your way. And, releasing the GIL means you have to do the GIL's work. There is no free lunch. I am studying the operation of the processor in a very critical way to find out how I can make a possibly simultaneous implementation in the case of 1 Processor with only 1 Core using ( C ) or Cython itself. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
How do i add limits to this code ? | learn1 | 3 | 2,794 |
Feb-07-2020, 02:30 AM Last Post: stullis |
|
Error SQLite objects created in a thread can only be used in that same thread. | binhduonggttn | 3 | 19,355 |
Jan-31-2020, 11:08 AM Last Post: DeaD_EyE |