Detecting and interacting with long running process
I w开发者_开发问答ant 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?
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).
Well here is an idea...
- place a status somewhere else, that can be polled/queried.
- when the process starts, post the 'running' status.
- have the script check here to see if the process is running.
- 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.
精彩评论