Python:在主线程外等待sigchild

2024-04-27 02:19:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个任务调度器,它应该运行xml文件中描述的任务。 调度程序应该是多线程和异步的,以尽量减少等待的开销。 问题是os.wait*在没有子级运行时抛出OSError。你知道吗

所以,这是我的代码:

print("Waiting")
try:
    (pid, exit_status) = os.waitpid(-1, 0)
    exit_status >>= 8
except OSError:
    print("Got error")
    #when wait is called, and there is no child processes
    #OSError is being raised
    import time
    time.sleep(1)               
    continue

我想知道是否有可能消除sleep()调用。你知道吗


Tags: 文件程序timeisosstatusexitsleep