1樓:王加加
主線程讀取輸入,讀到回車,則終止子執行緒:
#!/usr/bin/python
import
threading
import
time
class
MyThread
(threading
.Thread
):def
__init__
(self,*
args,**
kwargs
):super
(MyThread
,self).
__init__(*
args,**
kwargs
)self
._stop_event
=threading
.Event
()def
stop
(self
):self
._stop_event
.set
()def
stopped
(self
):return
self
._stop_event
.is_set
()def
run(
self
):while
True:if
self
.stopped
():break
("Hello, world!"
)time
.sleep(1
('在while迴圈外做些什麼?')t1
=MyThread
()t1
.start
()time
.sleep(2
)ch=input
('按回車停止執行緒:\n'
)t1.stop
()t1
.join()
2樓:
import
thread
,time
definput_thread(L
):raw_input()L
.(None
)def
do_print
():L=
thread
.start_new_thread
(input_thread,(
L,))
while1:
time
.sleep(.
1)ifL
:break
"Hi Mom!"
do_print
()來自:continuing loop until input (python)
要怎麼樣挽回前任
LYYY 答應我先走出來,盡量克制自己想ta 做一些改變,比如去健身房,多讀書,多結識一些朋友,多接觸一些愛好,培養一些自己的小圈子,努力讓自己變優秀。偶爾逛逛ta的空間,點幾個贊,讓他對你產生想回訪的好奇。我不知道這有多大的概率,但在改變之路上你會發現,你看不上他了 超甜超可愛 今天是我跟我男朋友...
離婚要怎麼樣達到訴求?
正商觀察者 你描述的很多,但是還是沒有說明房子的購買時間。如果是婚前你個人購買,那麼該房產就屬於你的個人財產。但是,婚後共同還款部分,以及公升值部分應該給男方補償。根據 婚姻法解釋三 第五條規定,夫妻一方個人財產在婚後產生的收益,除孳息和自然增值外,應認定為夫妻共同財產。第十條規定,夫妻一方婚前簽訂...
要怎麼樣才能讓理性戰勝感性,怎麼樣才能讓自己別那麼感性?
程誠 1 冷靜 遇事要冷靜,這是基礎 冷靜不下來,你可以試試強制自己大腦數質數 狗頭 如果慌慌張張,急急忙忙,那肯定辦不好事 慢事急做,急事慢做 先冷靜下來 我要做什麼?怎麼做?結果會如何?冷靜下來什麼都好說 2 思考 遇事多思考,多方面思考 你崩潰或是心情不好,很大程度上是事實偏於你的理想造成的這...