获取[Errno 13]非阻塞读取权限

时间:2018-03-15 01:20:12

标签: python python-2.7 nonblocking

我正在尝试使用python-nonblock实现简单的非阻塞读取。我编写了以下代码(Python 2.7,Mac OSX):

from nonblock import nonblock_read
import subprocess
import time


def goSleep():
    print('Sleeping for a while! ...!')
    time.sleep(20)


def processData(data):
    print('This is my data ...!')
    print(data)


def doSecondaryTask():
    for i in range(1000):
        print('Count: %s\n' % i)
        time.sleep(3)


if __name__ == "__main__":
    pipe = subprocess.Popen(['filetest.txt'], stdout=subprocess.PIPE)
    while True:
        data = nonblock_read(pipe.stdout)
        if data is None:
            # All data has been processed and subprocess closed stream
            pipe.wait()
            break
        elif data:
            # Some data has been read
            processData(data)
        else:
            # No data is on buffer, but subprocess has not closed stream
            goSleep()

    # To prove that non-blocking read is working
    doSecondaryTask()

不幸的是,我收到以下错误:

Traceback (most recent call last):
  File "io.py", line 16, in <module>
    pipe = subprocess.Popen(['filetest.txt'], stdout=subprocess.PIPE)
  File "/anaconda/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/anaconda/lib/python2.7/subprocess.py", line 1024, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied

我不确定为什么会得到Permission denied!我用Google搜索了几页,但仍然看不到问题。真的很感激任何帮助。

0 个答案:

没有答案