0

I'm aware of the discussions around threading, multithreading, and multiprocessing in python, but my question is whether all instances of python that are called run in parallel? I'm not suggesting using a single python script to spawn many threads, but literally starting the same script a few times in different terminals. Will they be in true parallel? Just citing that this might be the same question with the answer, but my knowledge isn't sufficient to be sure. Or is the python interpreter locked so all processes no matter how they're started still need to use the same interpreter to operate?

Fonty
  • 239
  • 2
  • 11

1 Answers1

1

Maybe, but it doesn't really have anything to do with Python itself.

Depending on your system and your hardware, the different processes may run in parallel, but it depends. Take for example a single core machine with no threading (rare these days, but very possible): because it can only possibly run one process at a time, then there's no possible way it could run parallel. If you have an operating system and a shell that's smart, then it might run them in parallel, but there's nothing that says it must.

If I had to guess, I'd say you can safely your (remotely modern) machine does run the processes at the same time. However, if you're running it on some kind of embedded system this might not be the case.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
  • 1
    It's worth emphasizing for the OP's clarity that the content of this answer is for processes in general, and that there is nothing special about Python in this regard – Brian61354270 Jul 18 '23 at 01:20
  • Thanks to you both. I did just run a test by running the same script twice that produced 1M dummy events then processed those events and found pretty much what you found. Faster than one script processing 2M events, but slower than just one running to processing 1M. So yes, it appears parallel, but some overhead must happen to get the work done on both I guess. The difference for 2 scripts x1M events is about the same time as a context switch (~10us) per 'event' compared to 1 script x1M events. – Fonty Jul 18 '23 at 01:27
  • @Brian61354270 I tried to do that with the first line "Maybe, but it doesn't really have anything to do with Python itself". Honestly asking for suggestions, what should I change to make it clearer? – Michael M. Jul 18 '23 at 02:42