Read file with timeout in Python

后端 未结 3 1567
甜味超标
甜味超标 2020-12-03 17:33

Within Linux, there is a file, /sys/kernel/debug/tracing/trace_pipe, which as the name says, is a pipe. So, let\'s say I want to read the first 50 bytes from it

3条回答
  •  旧时难觅i
    2020-12-03 18:06

    f = os.open("/sys/kernel/debug/tracing/trace_pipe", os.O_RDONLY|os.O_NONBLOCK)
    

    Should prevent blocking (works in Unix only).. No need for select here..

提交回复
热议问题