-2

Hi I have a Server/client model using SocketServer module. The server job is to receive test name from the clients and launch the test. the test is launched using subprocess module. I would like the server to keep answering clients and any new jobs to be stacked on a list or queue and launch one after the other, the only restriction I have is the server should not launch the test unless currently running one is completed.

Thanks

H kantana
  • 23
  • 3

2 Answers2

0

You can use the module

multiprocessing
for starting new processes. On the server-side, you would have a variable which refers to the current running process. You can still have your SocketServer running and accepting requests and storing them in a list. Every second (or whatever you want), in another thread, you would check if the current process is dead or not by calling isAlive(). If it is dead, then just simply run the next test on the list.

Another way to do it (better), is that on the third thread (the one that checks), you call .join() from the process so that it will only call the next line of code once the current process is dead. That way you don't have to keep checking every second or whatever and it is more efficient.

Leonid
  • 708
  • 5
  • 12
0

What you might want to do is:

  1. Get test name in server socket, put it in a Queue
  2. In a separate thread, read test names from the Queue one by one
  3. Execute the process and wait for it to end using communicate()
  4. Keep polling Queue for new tests, repeat steps 2, 3 if test names are available
  5. Meanwhile server continues receiving and putting test names in Queue
Community
  • 1
  • 1
S Raghav
  • 1,386
  • 1
  • 16
  • 26