在一些 Python 代码中,我fork
在子进程中做一些处理,而父进程等待它退出。它没有exec
在fork
.
我在 PyUnit 中测试此代码时遇到问题,因为当子进程以 显式退出时sys.exit
,它会创建一个 PyUnit 错误。
下面的代码产生了问题
class TestClass(TestCase):
def test(self):
pid = os.fork()
if pid == 0:
sys.exit(0)
else:
os.waitpid(pid,0)
这是错误
Traceback (most recent call last):
File "test.py", line 15, in test
sys.exit(0)
SystemExit: 0
----------------------------------------------------------------------
Ran 1 test in 0.007s
FAILED (errors=1)
如果子进程显式退出,是否有某种方法可以避免 PyUnit 测试失败?