Can';t kill macOS python进程

Can';t kill macOS python进程,python,macos,multiprocessing,python-3.7,Python,Macos,Multiprocessing,Python 3.7,我在使用Python API时遇到了问题,这会导致无法杀死的进程。我每个API执行使用一个进程。如果API能够正常工作,这将非常有效。但是,当API无法建立连接时,就会出现问题 我有一个主进程,它启动所有其他API进程: > ps ax | grep python 3431 s000 S+ 0:06.14 .../python3.7 -u .../main.py -> Main process 当成功连接到API(例如once实例)时,我会得到以下结果: > ps

我在使用Python API时遇到了问题,这会导致无法杀死的进程。我每个API执行使用一个进程。如果API能够正常工作,这将非常有效。但是,当API无法建立连接时,就会出现问题

我有一个主进程,它启动所有其他API进程:

> ps ax | grep python
   3431 s000 S+ 0:06.14 .../python3.7 -u .../main.py   -> Main process
当成功连接到API(例如once实例)时,我会得到以下结果:

> ps ax | grep python
   3431 s000 S+ 0:12.59 .../python3.7 -u .../main.py   -> Main process
   3506 s000 S+ 0:00.34 .../python3.7 -u .../main.py   -> API connection process
> ps ax | grep python
   3431 s000 R+ 1:00.51 .../python3.7 -u .../main.py   -> Main process
   3594 s000 U+ 0:00.02 .../python3.7 -u .../main.py   -> API connection process, where connection FAILED
   3595 s000 R+ 0:03.10 .../python3.7 -u .../main.py   -> API connection process, where connection was established
   3596 s000 S+ 0:01.69 .../python3.7 -u .../main.py   -> API connection process, where connection was established
如预期的那样,关闭成功的连接将终止API进程。没有僵尸进程出现

但是,如果我开始使用3个API实例(这是可能的),则API能够与其中两个实例/进程正确连接,但在其中一个实例/进程中失败。当所有进程都在运行时,我会得到以下结果:

> ps ax | grep python
   3431 s000 S+ 0:12.59 .../python3.7 -u .../main.py   -> Main process
   3506 s000 S+ 0:00.34 .../python3.7 -u .../main.py   -> API connection process
> ps ax | grep python
   3431 s000 R+ 1:00.51 .../python3.7 -u .../main.py   -> Main process
   3594 s000 U+ 0:00.02 .../python3.7 -u .../main.py   -> API connection process, where connection FAILED
   3595 s000 R+ 0:03.10 .../python3.7 -u .../main.py   -> API connection process, where connection was established
   3596 s000 S+ 0:01.69 .../python3.7 -u .../main.py   -> API connection process, where connection was established
关闭API的连接会给我带来麻烦:

> ps ax | grep python
   3431 s000 R+ 2:52.01 .../python3.7 -u .../main.py   -> Main process
   3594 s000 U+ 0:00.02 .../python3.7 -u .../main.py   -> API connection process, where connection FAILED
   3595 s000 Z+ 0:00.00 (python3.7)   -> API connection process (zombie), where connection was established
   3596 s000 Z+ 0:00.00 (python3.7)   -> API connection process (zombie), where connection was established
> ps aux | grep -w Z
   3595 0,0 0,0 0 0 s000 Z+ 10:04 0:00.00 (python3.7)  -> API process where connection was established
   3596 0,0 0,0 0 0 s000 Z+ 10:04 0:00.00 (python3.7)  -> API process where connection was established
我曾尝试过从Stack Overflow的前几篇文章中获得建议,但没有成功。这是我最好的尝试,但没有成功:

> kill -9 3594  -> kill API process where connection FAILED
> ps ax | grep python
   3431 s000 R+ 1:00.51 .../python3.7 -u .../main.py   -> Main process
   3594 s000 ?E+ 0:00.00 (python3.7)   -> API connection process, where connection FAILED
   3595 s000 z+ 0:00.00 (python3.7)   -> API connection process, where connection was established
   3596 s000 z+ 0:00.00 (python3.7)   -> API connection process, where connection was established
> ps aux | grep -w Z
   3595 0,0 0,0 0 0 s000 Z+ 10:04 0:00.00 (python3.7)   -> API connection process, where connection was established
   3596 0,0 0,0 0 0 s000 Z+ 10:04 0:00.00 (python3.7)   -> API connection process, where connection was established
> kill -1 3431   -> Kill main process
> ps aux | grep -w Z
   no processes
> ps ax | grep python
   3594 s000 ?E+ 0:00.00 (python3.7)  -> API connection process, where connection FAILED
> kill -9 3594
> ps ax | grep python
   3594 s000 ?E+ 0:00.00 (python3.7)  -> API connection process, where connection FAILED
> ps o ppid 3594
   PID 1
这些进程是用fork方法启动的(使用Python的
multiprocessing
library)。拥有这些不可终止进程的问题是,在主进程中,我有一个websocket连接,即使我终止了主进程,该不可终止进程也与它有一些连接,这使得websocket连接永远保持活跃。我不能以任何方式终止这个过程。唯一的方法是强制重新启动计算机


有什么帮助吗?

请提供。不幸的是,没有办法复制,因为我无法共享API,要使用它,您需要三台10万欧元的设备。我尽可能多地分享了有关流程的详细信息。我打赌问题与这些设备无关,因此您可以尝试隔离有问题的代码,并制作一些合成(但有效)示例。目前我甚至不知道在使用什么Python库。我如何才能模拟这样一个不可杀死的过程?我试过了,但运气不好——我总是能杀死它。你有没有想过这些设备中有一个是有缺陷的?相关:请提供。不幸的是,没有办法复制这一点,因为我无法共享API,要使用它,您需要三台10万欧元的设备。我尽可能多地分享了有关流程的详细信息。我打赌问题与这些设备无关,因此您可以尝试隔离有问题的代码,并制作一些合成(但有效)示例。目前我甚至不知道在使用什么Python库。我如何才能模拟这样一个不可杀死的过程?我试过了,但运气不好——我总是能杀死它。你有没有想过这些设备中有一个是有缺陷的?相关的: