1.为什么下面使用该concurrent.futures模块的Python代码永远挂起?
import concurrent.futures
class A:
def f(self):
print("called")
class B(A):
def f(self):
executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)
executor.submit(super().f)
if __name__ == "__main__":
B().f()
该调用引发了一个不可见的异常[Errno 24] Too many open files(要查看它,请将行替换为executor.submit(super().f))print(executor.submit(super().f).exception())。
但是,按预期替换ProcessPoolExecutor为ThreadPoolExecutor“称为”的打印件。
2.为什么下面使用该multiprocessing.pool模块的Python代码会引发异常AssertionError: daemonic processes are not allowed to have children?
import multiprocessing.pool
class A:
def f(self):
print("called")
class B(A):
def f(self):
pool = multiprocessing.pool.Pool(2)
pool.apply(super().f)
if __name__ == "__main__":
B().f()
但是,按预期替换Pool为ThreadPool“称为”的打印件。
环境:CPython 3.7,MacOS 10.14。