interrupt_mainºÃÏñûÓÃ
interrupt_mainµÄ×÷ÓÃÊÇ:Raise a KeyboardInterrupt in the main thread.ÏÂÃæµÄ³ÌÐòÊÔͼÀûÓÃ×ÓÏß³ÌÖе÷ÓÃinterrupt_main(),ÖжÏÖ÷Ïß³ÌÖеÄraw_input(),ÓÃÓÚÏÞ¶¨10sÄÚÊäÈëÄÚÈÝ,½á¹û10sºóÒÀȻͣÁôÔÚÊäÈë״̬,³¬Ê±ºóÊäÈë»Ø³µºó×ÓÏß³ÌÖвúÉúµÄÖÐ¶Ï²ÅÆð×÷ÓÃ,Ææ¹ÖÁË!
[CODE]
from thread import interrupt_main,start_new_thread
from time import sleep
flag = 1
def timeout( secs ):
global flag
sleep(secs)
if(flag):
print "timeout"
interrupt_main( )
print "interrupt_main"
def lt_input():
global flag
flag = 1
start_new_thread(timeout,(10,))
try:
s = raw_input("input in 10s :")
flag = 0
except:
s = "no"
print s
lt_input()
[/CODE]
Ò³:
[1]