Python Forum
attempted multithread doesn't multithread
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
attempted multithread doesn't multithread
#1
import threading,time

def simple_task(s):
      for j in range(5):
          print(s)
          time.sleep(0.5)

n=5
thread_list=[]

for i in range(n):
     t=threading.Thread(target=simple_task(i))
     t.start()
     thread_list.append(t)
expected result
 0,1,2,3,4,0,1,2....etc
actual
 0,0,0,0,0,1,1,1 etc

I've tried adding t.daemon=True, that doesn't change the result. I seem to be missing something. But haven't a clue what. Anyone know? thx
Reply


Messages In This Thread
attempted multithread doesn't multithread - by meems - Dec-10-2017, 12:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I multithread to optimize a groupby task: davisc4468 0 742 Jun-30-2023, 02:45 PM
Last Post: davisc4468
  How to measure execution time of a multithread loop spacedog 2 2,927 Apr-24-2021, 07:52 AM
Last Post: spacedog
  Why the multithread does not reduce the execution time? Nicely 2 2,526 Nov-23-2019, 02:28 PM
Last Post: Nicely
  multithread or multicore Chris2018 1 2,217 Oct-11-2018, 06:52 PM
Last Post: Larz60+
  ValueError: Attempted relative import in non-package JoeB 1 11,993 Mar-08-2018, 11:01 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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