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:
- Error in installing pywin32 under Windows: close failed in file object D estructor:sys.excepthook is missing lost sys.stderr
- Realize the simplest recursive call, simulate exception in thread “main” java.lang.stackoverflowerror exception
- The solution of a Java exception has occurred. And error exception in thread when eclipse runs
- Error: Exception was raised when calling per-thread-terminate function in extension lrwreplaymain.dl
- In Python sys.argv Usage of
- [Solved] org.mongodb.driver.cluster – Exception in monitor thread while connecting to server node1:27017
- The web application [ROOT] appears to have started a thread named [RxIoScheduler-1 (Evictor)] but ha
- [Solved] Mac ES Startup Error: Exception in thread “main“ java.nio.file.NotDirectoryException
- Exception in thread “main“ java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to XXX
- How to Fix Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
- Memory error unhandled exception: 0xc0000005: read location: 0x00000
- Python Anaconda Spyder can’t display pictures by using Matplotlib. Error report solution: figures now render in the plots pane by default. To mak
- Unhandled exception: 0xc0000005: access violation while reading location 0x00000000
- Run with Python console solution is set by default for all projects in pcharm
- Fatal error in GC getthreadcontext failed bug exception.
- Dxly solves the fatal error of AutoCAD2006: unhandled access violation reading 0x0000 exception at 6532b0h.
- C / C + + error handling (document): unhandled exception: 0xc0000005: access violation while reading location 0x00000000
- Python program exit: OS_ Exit() and sys.exit ()
- Three possibilities of “unhandled exception: 0xc0000005: access conflict when reading location 0x00000000”
- Fatal signal 6 (sigabrt), code – 6 in TID 28957 (thread-2)