I am a novice user of python multithreading/multiprocessing, so please bear with me. I would like to solve the following problem and I need some help/suggestions in this regard. Let me describe in brief:
I would like to start a python script which does something in the beginning sequentially.
After the sequential part is over, I would like to start some jobs in parallel.
- Assume that there are four parallel jobs I want to start.
- I would like to also start these jobs on some other machines using "lsf" on the computing cluster.My initial script is also running on a ” lsf” machine.
- The four jobs which I started on four machines will perform two logical steps A and B---one after the other.
- When a job started initially, they start with logical step A and finish it.
- After every job (4jobs) has finished the Step A; they should notify the first job which started these. In other words, the main job which started is waiting for the confirmation from these four jobs.
- Once the main job receives confirmation from these four jobs; it should notify all the four jobs to do the logical step B.
- Logical step B will automatically terminate the jobs after finishing the task.
- Main job is waiting for the all jobs to finish and later on it should continue with the sequential part.
An example scenario would be:
- Python script running on an “lsf” machine in the cluster starts four "tcl shells" on four “lsf” machines.
- In each tcl shell, a script is sourced to do the logical step A.
- Once the step A is done, somehow they should inform the python script which is waiting for the acknowledgement.
- Once the acknowledgement is received from all the four, python script inform them to do the logical step B.
- Logical step B is also a script which is sourced in their tcl shell; this script will also close the tcl shell at the end.
- Meanwhile, python script is waiting for all the four jobs to finish.
- After all four jobs are finished; it should continue with the sequential part again and finish later on.
Here are my questions:
I am confused about---should I use multithreading/multiprocessing. Which one suits better? In fact what is the difference between these two? I read about these but I wasn't able to conclude.
What is python GIL? I also read somewhere at any one point in time only one thread will execute. I need some explanation here. It gives me an impression that I can't use threads.
Any suggestions on how could I solve my problem systematically and in a more pythonic way. I am looking for some verbal step by step explanation and some pointers to read on each step. Once the concepts are clear, I would like to code it myself.
Thanks in advance.