Mrzhang0320

Mrzhang0320

V2EX 第 284881 号会员,加入于 2018-01-20 23:13:49 +08:00
今日活跃度排名 22072
31 S
lasspass 这个插件谁用过
信息安全  •  Mrzhang0320  •  2018-02-26 16:09:10 PM  •  最后回复来自 xsn
11
迷茫!!!
Python  •  Mrzhang0320  •  2018-03-01 18:27:43 PM  •  最后回复来自 longchisihai
30
请教各位 V 友一个服务器问题
  •  1   
    程序员  •  Mrzhang0320  •  2018-01-31 23:49:05 PM  •  最后回复来自 salmon5
    2
    萌新请教一个 Python socket 问题
    Python  •  Mrzhang0320  •  2018-01-30 19:40:55 PM  •  最后回复来自 ysc3839
    8
    iPhone8 用了两个多月了,指纹识别不准!
  •  2   
    iPhone  •  Mrzhang0320  •  2018-01-26 17:17:58 PM  •  最后回复来自 w3sy
    27
    Mrzhang0320 最近回复了
    @skylancer 但是你怎么获取到那个 pid 呢,重启之后 pid 改变了
    @ThinkZ 对诶
    @Thanks 好的谢谢,我试一下加个 try ;确实在上一次打印 pids 时,存在这个 pid ;然后就出错了;
    @ThinkZ 在上一次打印的 pids 中 这个不存在的进程 pid 还是有的
    @ThinkZ kill 完了,然后也重启启动了,之后就出现这样的
    Traceback (most recent call last):
    File "D:\python\lib\site-packages\psutil\_pswindows.py", line 635, in wrapper
    return fun(self, *args, **kwargs)
    File "D:\python\lib\site-packages\psutil\_pswindows.py", line 821, in create_time
    return cext.proc_create_time(self.pid)
    ProcessLookupError: [Errno 3] No such process

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "D:\python\lib\site-packages\psutil\__init__.py", line 368, in _init
    self.create_time()
    File "D:\python\lib\site-packages\psutil\__init__.py", line 699, in create_time
    self._create_time = self._proc.create_time()
    File "D:\python\lib\site-packages\psutil\_pswindows.py", line 640, in wrapper
    raise NoSuchProcess(self.pid, self._name)
    psutil._exceptions.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=11812)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "jiankong.py", line 40, in <module>
    main()
    File "jiankong.py", line 12, in main
    p = psutil.Process(pid)
    File "D:\python\lib\site-packages\psutil\__init__.py", line 341, in __init__
    self._init(pid)
    File "D:\python\lib\site-packages\psutil\__init__.py", line 381, in _init
    raise NoSuchProcess(pid, None, msg)
    psutil._exceptions.NoSuchProcess: psutil.NoSuchProcess no process found with pid 11812
    import os,psutil,time,signal

    ProList = []
    i = 0
    ProcessName = "1.exe"
    ProgramPath = r"E:\test\1.exe"

    #检测并启动进程
    def main():
    print(psutil.pids())
    for pid in psutil.pids():
    p = psutil.Process(pid)
    ProList.append(str(p.name()))
    if p.name() == ProcessName:
    kill(pid)
    print("111")

    def kill(pid):
    try:
    print("killing Server...")
    os.kill(pid, signal.SIGTERM)
    time.sleep(6)
    print("Restart Server Success...")
    os.startfile(ProgramPath)
    print(pid)
    except e:
    print("没有%s 进程" % pid)

    if __name__=="__main__":
    while True:
    main()
    i = i+1
    print(i)
    time.sleep(3)
    @octobersnow 不好意思,新人,刚学会用语法上图片。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1047 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:31 · PVG 06:31 · LAX 14:31 · JFK 17:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.