I have two Python concurrent-related questions that want someone's clarification.
Task Description:
Let us say I set up two py scripts. Each script is running two IO-bound tasks (API Calls) with multithreading (max workers as 2).
Questions:
If I don't use a virtual environment, and run both scripts through the global Python interpreter (the one in system-wide Python installation). Does this make the task I described the single process and multithreaded? Since we are using one interpreter (single process) and have two scripts running a total of 4 threads?
If I use the Pycharm to create two separate projects where each project has its own Python interpreter. Does such a setting turn the task into multiprocessing and multithreaded? Since we have two Python interpreters running and each running two threads?
CodePudding user response:
Each running interpreter process has its own GIL that's separate from any other GILs in other interpreters that happen to be running. The project and virtual environment associated with the script being run are irrelevant. Virtual environments are to isolate different versions of Python and libraries so libraries from one project don't interfere with libraries in another.
If you run two scripts separately like python script.py
, this will start two independent interpreters that will be unaffected by the other.
Does such a setting turn the task into multiprocessing and multithreaded?
I don't think it's really meaningful to call it a "multiprocess task" if the two processes are completely independent of each other and never talk. You have multiple processes running, but "multiprocessing" within the context of a Python program typically means one coherant program that makes use of multiple processes for a common task.