草庐IT

DummyExecutor

全部标签

python - `DummyExecutor` 用于 Python 's ` future `

Python的futures包允许我们使用ThreadPoolExecutor和ProcessPoolExecutor并行执行任务。但是,为了调试,有时用虚拟并行临时替换真正的并行很有用,虚拟并行在主线程中以串行方式执行任务,而不会产生任何线程或进程。有没有DummyExecutor的实现? 最佳答案 应该这样做:fromconcurrent.futuresimportFuture,ExecutorfromthreadingimportLockclassDummyExecutor(Executor):def__init__(self

python - `DummyExecutor` 用于 Python 's ` future `

Python的futures包允许我们使用ThreadPoolExecutor和ProcessPoolExecutor并行执行任务。但是,为了调试,有时用虚拟并行临时替换真正的并行很有用,虚拟并行在主线程中以串行方式执行任务,而不会产生任何线程或进程。有没有DummyExecutor的实现? 最佳答案 应该这样做:fromconcurrent.futuresimportFuture,ExecutorfromthreadingimportLockclassDummyExecutor(Executor):def__init__(self