psutil异常错误 - 没有这样的过程

时间:2017-11-22 05:56:17

标签: python raspberry-pi

我在Raspberry Pi上有两个独立的Python脚本,它们通过调用raspistill os函数异步访问RPi摄像头。我以为我有一个函数工作,可以检查raspistill进程是否正在运行,如果是,将等待它清除,以便它可以运行。在这两个脚本中,我都包含以下函数:

from time import sleep
import psutil

def camFree():
    for pid in psutil.pids():
        p = psutil.Process(pid)
        if(p.name() == 'raspistill'):
            return False
    return True

然后,我在我的代码中将以下调用放在raspistill调用之前,如下所示:

while(camFree() is False):           # wait until camera is not being used
    time.sleep(1)

我每分钟都会运行此脚本来拍照,并将脚本的输出重定向到日志文件。大多数时候,我对脚本运行没有任何问题。但是,偶尔,并不一定在其他相机脚本运行时,我会收到如下错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/psutil/_pslinux.py", line 1369, in wrapper
    return fun(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/psutil/_pslinux.py", line 1546, in create_time
    values = self._parse_stat_file()
  File "/usr/local/lib/python3.4/dist-packages/psutil/_common.py", line 337, in wrapper
    return fun(self)
  File "/usr/local/lib/python3.4/dist-packages/psutil/_pslinux.py", line 1408, in _parse_stat_file
    with open_binary("%s/%s/stat" % (self._procfs_path, self.pid)) as f:
  File "/usr/local/lib/python3.4/dist-packages/psutil/_pslinux.py", line 190, in open_binary
    return open(fname, "rb", **kwargs)
FileNotFoundError: [Errno 2] No such file or directory: '/proc/15538/stat'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/psutil/__init__.py", line 428, in _init
    self.create_time()
  File "/usr/local/lib/python3.4/dist-packages/psutil/__init__.py", line 754, in create_time
    self._create_time = self._proc.create_time()
  File "/usr/local/lib/python3.4/dist-packages/psutil/_pslinux.py", line 1380, in wrapper
    raise NoSuchProcess(self.pid, self._name)
psutil.NoSuchProcess: psutil.NoSuchProcess process no longer exists (pid=15538)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/projects/daytimelapse/daytimelapse.py", line 189, in <module>
    while(camFree() is False):           # wait until camera is not being used
  File "/home/pi/projects/daytimelapse/daytimelapse.py", line 108, in camFree
    p = psutil.Process(pid)
  File "/usr/local/lib/python3.4/dist-packages/psutil/__init__.py", line 401, in __init__
self._init(pid)
  File "/usr/local/lib/python3.4/dist-packages/psutil/__init__.py", line 441, in _init
    raise NoSuchProcess(pid, None, msg)
psutil.NoSuchProcess: psutil.NoSuchProcess no process found with pid 15538

任何帮助将不胜感激!谢谢,戴夫

0 个答案:

没有答案