python如何手动实现阻塞
伊谢尔伦
伊谢尔伦 2017-04-18 10:31:04
0
2
542

python 如何手动实现阻塞?

令py脚本一直阻塞直到强制退出(KeyboardInterrupt)

之前用

while True:
    pass

发现cpu占用太高了。。。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
PHPzhong

1. Use time.sleep

while True:
    # 等待一年
    time.sleep(60*60*24*365)
    
# 直接等待一百年
time.sleep(60*60*24*365*100)

2.Use threading.Condition

condition=threading.Condition()
condition.acquire()
condition.wait()

2. Use wait for keyboard response

Python implements pressing any key to continue

黄舟
while True:
    time.sleep(1)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!