import time
import thread
def timer(no, interval):
cnt = 0
while cnt<10:
print 'Thread:(%d) Time:%s/n'%(no, time.ctime())
time.sleep(interval)
cnt+=1
thread.exit_thread()
def test(): #Use thread.start_new_thread() to create 2 new threads
thread.start_new_thread(timer, (1,1))
thread.start_new_thread(timer, (2,2))
if __name__=='__main__':
test()
There is an error
Unhandled exception in thread started by
Error in sys.excepthook:
Original exception was:
Solution: Change the main function to
<pre>if __name__=='__main__':
test()
time.sleep(3)
As for why sleep for a few seconds, not clear
The message on the Web is that threading is not recommended, use the threading.thread class instead
Read More:
- Fatal error in GC getthreadcontext failed bug exception.
- close failed in file object destructor: IOError: [Error 10] No child processes
- Solution to the failure of creating bitmap with multithreaded OpenGL
- pip Import Error:cannot import Name main solution
- pthread_ Introduction and application of join function
- The difference between sleep() and wait() in Java
- Could not start Quartz Scheduler after delay; nested exception is org.quartz.SchedulerException:
- A solution to [error] LD returned 1 exit status
- [Error resolution] paramiko.ssh_exception.SSHException: Error reading SSH protocol banner setting
- Python2 PicklingError: Can‘t pickle <type ‘instancemethod‘>: attribute lookup __builtin__.instanceme
- panic: runtime error: index out of range
- python3 request module https certificate verify failed error
- Several calculation methods of Python execution time
- Python program exit: OS_ Exit() and sys.exit ()
- Linux shell loop in a line for while
- Socket Error 104 bug
- 0xc0000005: an access conflict occurred while reading location 0x00000020
- Tensorflow in function tf.Print Method of outputting intermediate value
- Go run error go run: cannot run non main package
- What are the common clearing commands in MATLAB?