JacquesB
JacquesB

Reputation: 42649

Detecting and interacting with long running process

I want a script to start and interact with a long running process. The process is started first time the script is executed, after that the script can be executed repeatedly, but will detect that the process is already running. The script should be able to interact with the process. I would like this to work on Unix and Windows.

I am unsure how I do this. Specifically how do I detect if the process is already running and open a pipe to it? Should I use sockets (e.g. registering the server process on a known port and then check if it responds) or should I use "named pipes"? Or is there some easier way?

Upvotes: 0

Views: 331

Answers (2)

Alex Martelli
Alex Martelli

Reputation: 881635

Sockets are easier to make portable between Windows and any other OS, so that's what I would recommend it over named pipes (that's why e.g. IDLE uses sockets rather than named pipes -- the latter require platform-dependent code on Windows, e.g. via ctypes [[or third-party win32all or cython &c]], while sockets just work).

Upvotes: 2

Randy
Randy

Reputation: 16677

Well here is an idea...

  1. place a status somewhere else, that can be polled/queried.
  2. when the process starts, post the 'running' status.
  3. have the script check here to see if the process is running.
  4. I would also use a seperate place to post control values. e.g. set a value to the 'control set' and have the process look for those values whenever it gets to decision points in its runtime behavior.

Upvotes: 0

Related Questions