3

问一下大佬们, 如何保证在 windows 系统上面这个 Python 进程最多只有一个在运行

 3 years ago
source link: https://www.v2ex.com/t/782998
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Python

问一下大佬们, 如何保证在 windows 系统上面这个 Python 进程最多只有一个在运行

  18870715400 · 2 天前 · 870 次点击

例如下面的代码文件 hello.py


import time

import subproctitle
while 1:
    pass

运行该文件 python hello.py , 如果当前系统已经有这个进程在运行了, 则直接这个文件报错不运行或者其它的, 但是如果没有的话则启动这个文件, 一开始用 setproctitle 这个文件, 设置一个专门的进程名字来检测, 但是 setproctitle 在 windows 上好像 失效了, 那么还有什么方法么?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK