concurrent.futures

Why lambda inside map is not running?

≡放荡痞女 提交于 2020-11-28 08:57:25
问题 I am trying to learn concurrency and lambdas in java 8. But my code is not entering lambda block inside map. List<Book> bookList = new ArrayList<Book>(); isbnList .stream() .map(isbn -> (CompletableFuture.supplyAsync( () -> { try { List<String> pageContents = getUrlContents(webLink + isbn); return new Book( parseBookTitle(pageContents), isbn, parseRank(pageContents) ); } catch (IOException ex) { return null; } })).thenApply(a -> bookList.add(a)) ); While debugging, code is exiting at .map

Getting “Queue objects should only be shared between processes through inheritance” but I'm not using a Queue

删除回忆录丶 提交于 2020-08-26 02:55:08
问题 I am trying to use a ProcessPoolExecutor, but I am getting the error "Queue objects should only be shared between processes through inheritance", but I am not using a Queue (at least not explicitly). I can't find anything that explains what I am doing wrong. Here is some code that demonstrates the issue (not my actual code): from concurrent.futures import ProcessPoolExecutor, as_completed class WhyDoesntThisWork: def __init__(self): self.executor = ProcessPoolExecutor(4) def execute_something

Getting “Queue objects should only be shared between processes through inheritance” but I'm not using a Queue

久未见 提交于 2020-08-26 02:54:46
问题 I am trying to use a ProcessPoolExecutor, but I am getting the error "Queue objects should only be shared between processes through inheritance", but I am not using a Queue (at least not explicitly). I can't find anything that explains what I am doing wrong. Here is some code that demonstrates the issue (not my actual code): from concurrent.futures import ProcessPoolExecutor, as_completed class WhyDoesntThisWork: def __init__(self): self.executor = ProcessPoolExecutor(4) def execute_something

Python - Properly Kill/Exit Futures Thread?

对着背影说爱祢 提交于 2020-08-24 07:17:20
问题 I was previously using the threading.Thread module. Now I'm using concurrent.futures -> ThreadPoolExecutor . Previously, I was using the following code to exit/kill/finish a thread: def terminate_thread(thread): """Terminates a python thread from another thread. :param thread: a threading.Thread instance """ if not thread.isAlive(): return exc = ctypes.py_object(SystemExit) res = ctypes.pythonapi.PyThreadState_SetAsyncExc( ctypes.c_long(thread.ident), exc) if res == 0: raise ValueError(

A ThreadPoolExecutor inside a ProcessPoolExecutor

倾然丶 夕夏残阳落幕 提交于 2020-08-21 09:44:08
问题 I am new to the futures module and have a task that could benefit from parallelization; but I don't seem to be able to figure out exactly how to setup the function for a thread and the function for a process. I'd appreciate any help anyone can shed on the matter. I'm running a particle swarm optimization (PSO). Without getting into too much detail about PSO itself, here's the basic layout of my code: There is a Particle class, with a getFitness(self) method (which computes some metric and