开发者

Detecting and interacting with long running process

开发者 https://www.devze.com 2023-01-03 12:42 出处:网络
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 d

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...

  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.
0

精彩评论

暂无评论...
验证码 换一张
取 消