10得票1回答
未来在等待后引发 TypeError 错误

我正在尝试使用并行处理来优化一些现有代码中的昂贵操作。以前我使用 concurrent.futures 来实现,但那时它们没有返回任何结果。 这次我想要管理结果,但当打印我的收集物时,我得到的是每个future的状态,例如 <Future at 0x... state=finished...

10得票4回答
Python ThreadPoolExecutor 终止所有线程

我正在运行一段Python代码,其中通过线程池执行器运行多个线程。每个线程都应该执行一个任务(例如获取网页)。我想要做到的是终止所有线程,即使其中一个线程失败了。例如: with ThreadPoolExecutor(self._num_threads) as executor: j...

9得票5回答
如何在Python的concurrent.futures中打破time.sleep()函数

我正在尝试使用concurrent.futures。 目前我的future调用了time.sleep(secs)。 似乎Future.cancel()的作用不及我所想。 如果future已经在执行,那么time.sleep()将无法被取消。 wait()的超时参数同样无法取消time....

9得票1回答
CompletableFuture没有执行。如果我使用ExecutorService池,它能够按预期工作,但是使用常见的ForkJoinPool却不能。

我正在尝试运行以下类,但它在没有执行CompletableFuture的情况下终止了。 public class ThenApplyExample { public static void main(String[] args) throws Exception { //Execu...

9得票2回答
如何在Python 3中使用队列与并发Future ThreadPoolExecutor?

我正在使用简单的线程模块来执行并发任务。现在我想利用concurrent futures模块的优势。能否给我一个使用队列和并发库的示例呢? 我得到了TypeError: 'Queue' object is not iterable 我不知道如何迭代队列 代码片段: def run(it...

9得票4回答
在Futures.transform中,使用Function和AsyncFunction有什么区别?

我知道Function的apply方法同步返回一个对象,而AsyncFunction的apply是异步运行并返回一个Future。 您能给我举个例子,说明什么时候应该选择哪种方法吗? 我看到的一段代码片段大致如下: Futures.transform(someFuture, new As...

9得票6回答
Python中的多进程内多线程

我正在使用并发.futures模块进行多进程和多线程操作。我正在一台拥有8个核心、16GB RAM、英特尔i7第八代处理器的机器上运行。我在Python 3.7.2和Python 3.8.2上都尝试过。 import concurrent.futures import time def ...

8得票1回答
有效期限的未来与默认构造的未来

我正在学习并发编程课程中的期货。我的教授在幻灯片中这样说明: "Valid" futures are future objects associated to a  shared state, and are constructed by calling one of the followi...

8得票1回答
ThreadPoolExecutor + Requests == 死锁?

我有一段微小的代码,它向谷歌搜索服务发送了大量请求。 from concurrent.futures import ThreadPoolExecutor import requests import requests.packages.urllib3 requests.packages.u...

8得票2回答
如何修复concurrent.futures ProcessPoolExecutor中出现的BrokenProcessPool错误

使用concurrent.futures.ProcessPoolExecutor,我尝试并行运行第一段代码来执行函数"Calculate_Forex_Data_Derivatives(data,gride_spacing)"。当调用结果executor_list[i].result()时,我会...