如何让 Python 3.11.5 进程在 Monterey 12.6.8 上自行挂起?

问题描述 投票:0回答:1
#!/usr/bin/python3

import os
import time

os.system('/bin/kill -19 ' + str(os.getpid()))
time.sleep(2)

在 Linux 上,此脚本立即返回,暂停。在 Mac 上,此脚本等待两秒钟并退出,而不自行挂起。

如何才能在 Mac 上启用暂停行为?

TIA,

python python-3.x signals macos-monterey
1个回答
0
投票
MacOS 似乎不支持

IPC 信号

19
。您可以使用
-s SIGSTOP
暂停进程。


import os
import time

os.system(f'/bin/kill -s SIGSTOP {os.getpid()}')
time.sleep(2)
© www.soinside.com 2019 - 2024. All rights reserved.