Home > other >  Python multithreaded start up...
Python multithreaded start up...

Time:12-20

 import threading 
The import time

Sum=0
The lock=threading. The lock ()

Class My_Thread (threading. Thread) :
Def __init__ (self, start, end) :
Super () __init__ ()
Self. Start=start
The self. The end=end
Self. Part_sum=0
Def run (self) :
For I in range (self. The start, the self. The end + 1) :
Self. Part_sum +=I
Lock. Acquire ()
Global sum
The sum +=self. Part_sum
The lock release ()

If __name__=="__main__ ':
Start=time. Time ()

Target_num=10000
Thread_list=[]

I=0
The interval=1000

While True:
If I + interval> Target_num:
Thread_list. Append (My_Thread (I + 1, target_num))
Break
The else:
Thread_list. Append (My_Thread (I + 1, I + interval))
I +=interval

For single_thread thread_list in:
Single_thread. Start ()

For single_thread thread_list in:
Single_thread. The join ()

End=time. Time ()
Print (" time "+ STR (end - start) +" seconds ")


Error message:
PS D: \ VSCproject> & C:/Users/dragon/AppData/Local/designed/Python/Python38/Python. Exe d:/VSCproject/Python/test1. Py
Traceback (the most recent call last) :
The File "d:/VSCproject/python/test1. Py", line 39, in & lt; module>
Single_thread. Start ()
TypeError: 'int' object is not callable
PS D: \ VSCproject>

Good folks, this is where I went wrong?
  • Related