Python Forum
How to run multiple threads properly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run multiple threads properly
#7
from threading import Thread

import time

def PR01():
    k = 0
    while (k < 25000000):
        k = k + 1
        
def PR02():
    k = 0
    while (k < 25000000):
        k = k + 1        
    
# defining the time now in epoch format
def thetime():
    return int(time.time())
    
print "only start here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"   

task_start = thetime()

k = 0
while (k < 25000000):
    k = k + 1
    
k = 0
while (k < 25000000):
    k = k + 1


task_end = "%05d" % (thetime() - task_start,)
print("original = " + str(task_end))            

task_start = thetime()
p01 = Thread(name='PR01', target=PR01)
p02 = Thread(name='PR02', target=PR02)

p01.start()
p01.join()

p02.start()
p02.join()

task_end = "%05d" % (thetime() - task_start,)
print("processed 1 = " + str(task_end))    

print "only done here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Reply


Messages In This Thread
RE: How to run multiple threads properly - by wavic - Dec-22-2017, 07:38 AM
RE: How to run multiple threads properly - by mpd - Dec-22-2017, 12:41 PM
RE: How to run multiple threads properly - by wavic - Dec-22-2017, 02:42 PM
RE: How to run multiple threads properly - by cyberion1985 - Dec-29-2017, 09:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to separate a loop across multiple threads stylingpat 0 1,738 May-05-2021, 05:21 PM
Last Post: stylingpat
  Get average of multiple threads Contra_Boy 1 19,913 May-05-2020, 04:51 PM
Last Post: deanhystad
  stop multiple threads jeuvrey 5 3,509 Nov-15-2018, 01:34 PM
Last Post: jeuvrey
  Quitting multiple threads MuntyScruntfundle 3 2,744 Oct-17-2018, 05:14 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

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