Python Forum
Concurrent futures threading running at same speed as non-threading
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concurrent futures threading running at same speed as non-threading
#11
import concurrent.futures
from concurrent.futures import ThreadPoolExecutor

def add(args):
    print('inside add')
    return sum(args)

args = [(4, 2), (9, 3), (16, 2)]

with ThreadPoolExecutor(max_workers=5) as executor:
    for result in executor.map(add, args):
        print(result)
Output:
inside add inside add 6 inside add 12 18
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: Concurrent futures threading running at same speed as non-threading - by buran - May-03-2023, 07:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  threading native_id returning same value for all threads billykid999 2 1,287 May-04-2023, 06:40 AM
Last Post: billykid999
  Trouble with threading and reading variable from a different script Lembas 14 3,495 Apr-26-2023, 11:21 PM
Last Post: Lembas
  using threading.Timer for function korenron 1 1,342 Dec-20-2022, 01:09 PM
Last Post: ndc85430
  [Solved]Help with Threading Extra 7 2,155 Sep-05-2022, 05:29 PM
Last Post: Extra
Question Opencv and threading ethernel 4 194,708 Feb-25-2022, 06:06 PM
Last Post: ethernel
  Inconsistent counting / timing with threading rantwhy 1 1,851 Nov-24-2021, 04:04 AM
Last Post: deanhystad
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 4,168 Nov-12-2021, 09:55 PM
Last Post: snippsat
  Mult-threading and locking file mr_byte31 4 2,848 Oct-16-2021, 01:54 AM
Last Post: Larz60+
  Matplotlib Animation with Threading peterjv26 4 7,636 Oct-08-2021, 05:51 PM
Last Post: peterjv26
  Tutorials on sockets, threading and multi-threading? muzikman 2 2,267 Oct-01-2021, 08:32 PM
Last Post: muzikman

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020