can a python script know that another instance of the same script is running… and then talk to it?

前端 未结 4 1564
情歌与酒
情歌与酒 2021-02-02 01:23

I\'d like to prevent multiple instances of the same long-running python command-line script from running at the same time, and I\'d like the new instance to be able to send data

4条回答
  •  星月不相逢
    2021-02-02 01:32

    Sounds like your best bet is sticking with a pid file but have it not only contain the process Id - have it also include the port number that the prior instance is listening on. So when starting up check for the pid file and if present see if a process with that Id is running - if so send your data to it and quit otherwise overwrite the pid file with the current process's info.

提交回复
热议问题