非阻塞读取sys.stdin

创建日期: 2022-07-18 14:29 | 作者: 风波 | 浏览次数: 16 | 分类: Python

方法一:使用 select 模块

代码如下:

import sys
import select

if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
    print('Input is waiting to be read: ', sys.stdin.read())

参考:http://www.dsclose.com/linux/python/2016/04/26/non-blocking-reads-clearing-stdin-in-python.html

16 浏览
10 爬虫
0 评论