concurrent.futures

concurrent.futures.ThreadPoolExecutor doesn't print errors

狂风中的少年 提交于 2021-02-09 09:37:25
问题 I am trying to use concurrent.futures.ThreadPoolExecutor module to run a class method in parallel, the simplified version of my code is pretty much the following: class TestClass: def __init__(self, secondsToSleepFor): self.secondsToSleepFor = secondsToSleepFor def testMethodToExecInParallel(self): print("ThreadName: " + threading.currentThread().getName()) print(threading.currentThread().getName() + " is sleeping for " + str(self.secondsToSleepFor) + " seconds") time.sleep(self

Concurrent.futures opens new windows in tkinter instead of running the function

心已入冬 提交于 2021-01-29 20:40:47
问题 I am trying to run a function concurrently over multiple files in a gui using tkinter and concurrent.futures Outside of the GUI, this script works fine. However, whenever I translate it over into the GUI script, instead of running the function in parallel, the script opens up 5 new gui tkinter windows (the number of windows it opens is equal to the number of processors I allow the program to use). Ive looked over the code thoroughly and just cant understand why it is opening new windows as

Python ThreadPoolExecutor terminate all threads

假装没事ソ 提交于 2021-01-28 18:16:49
问题 I am running a piece of python code in which multiple threads are run through threadpool executor. Each thread is supposed to perform a task (fetch a webpage for example). What I want to be able to do is to terminate all threads, even if one of the threads fail. For instance: with ThreadPoolExecutor(self._num_threads) as executor: jobs = [] for path in paths: kw = {"path": path} jobs.append(executor.submit(start,**kw)) for job in futures.as_completed(jobs): result = job.result() print(result)

How to use concurrent.futures in Python

我的未来我决定 提交于 2021-01-28 08:44:18
问题 Im struggling to get multithreading working in Python. I have i function which i want to execute on 5 threads based on a parameter. I also needs 2 parameters that are the same for every thread. This is what i have: from concurrent.futures import ThreadPoolExecutor def do_something_parallel(sameValue1, sameValue2, differentValue): print(str(sameValue1)) #same everytime print(str(sameValue2)) #same everytime print(str(differentValue)) #different main(): differentValues = ["1000ms", "100ms",

Concurrent.futures code ends up with “BrokenProcessPool”

点点圈 提交于 2021-01-28 02:22:14
问题 Yesterday I asked a similar question and somebody suggested me to use concurrent.futures and asyncio. What I want is skipping the file if it takes too long to process. Here is my code: import os, glob import time import asyncio from concurrent.futures import ProcessPoolExecutor @asyncio.coroutine def coro(loop, of, filename): ex = ProcessPoolExecutor(4) yield from loop.run_in_executor(ex, os.system, "\"C:\\P.exe\" -o {} {}".format(of, filename)) for folder, subfolders, filenames in os.walk

Concurrent.futures code ends up with “BrokenProcessPool”

北城余情 提交于 2021-01-27 22:34:02
问题 Yesterday I asked a similar question and somebody suggested me to use concurrent.futures and asyncio. What I want is skipping the file if it takes too long to process. Here is my code: import os, glob import time import asyncio from concurrent.futures import ProcessPoolExecutor @asyncio.coroutine def coro(loop, of, filename): ex = ProcessPoolExecutor(4) yield from loop.run_in_executor(ex, os.system, "\"C:\\P.exe\" -o {} {}".format(of, filename)) for folder, subfolders, filenames in os.walk

python futures and tuple unpacking

故事扮演 提交于 2021-01-27 18:45:50
问题 What is an elagant/idiomatic way to achieve something like tuple unpacking with futures? I have code like a, b, c = f(x) y = g(a, b) z = h(y, c) and I would like to convert it to use futures. Ideally I would like to write something like a, b, c = ex.submit(f, x) y = ex.submit(g, a, b) z = ex.submit(h, y, c) The first line of that throws TypeError: 'Future' object is not iterable though. How can I get a,b,c without having to make 3 additional ex.submit calls? ie. I would like to avoid having

gRPC Python thread_pool vs max_concurrent_rpcs

最后都变了- 提交于 2021-01-22 06:31:24
问题 When launching a Python grpc.server , what's the difference between maximum_concurrent_rpcs and the max_workers used in the thread pool. If I want maximum_concurrent_rpcs=1 , should I still provide more than one thread to the thread pool? In other words, should I match maximum_concurrent_rpcs to my max_workers , or should I provide more workers than max concurrent RPCs? server = grpc.server( thread_pool=futures.ThreadPoolExecutor(max_workers=1), maximum_concurrent_rpcs=1, ) 回答1: If your

gRPC Python thread_pool vs max_concurrent_rpcs

杀马特。学长 韩版系。学妹 提交于 2021-01-22 06:29:30
问题 When launching a Python grpc.server , what's the difference between maximum_concurrent_rpcs and the max_workers used in the thread pool. If I want maximum_concurrent_rpcs=1 , should I still provide more than one thread to the thread pool? In other words, should I match maximum_concurrent_rpcs to my max_workers , or should I provide more workers than max concurrent RPCs? server = grpc.server( thread_pool=futures.ThreadPoolExecutor(max_workers=1), maximum_concurrent_rpcs=1, ) 回答1: If your

Why lambda inside map is not running?

*爱你&永不变心* 提交于 2020-11-28 08:57:47
问题 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