Skip to content

from npy_PyFile_Dup2 check the seekable attribute #12309

Description

@hmaarrfk

Should from npy_PyFile_Dup2 check the seekable attribute:

unbuf = PyObject_IsInstance(file, io_raw);

For example

import subprocess as sp
a = sp.Popen(['echo hello world this is so great'], stdout=sp.PIPE, shell=True)
print(a.stdout.seekable())
print(a.stdout)
import numpy as np
np.fromfile(a.stdout, dtype='uint8', count=10)
False
<_io.BufferedReader name=13>
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-ab1c03142ecc> in <module>
      4 print(a.stdout)
      5 import numpy as np
----> 6 np.fromfile(a.stdout, dtype='uint8', count=10)

OSError: obtaining file position failed

but this works

import subprocess as sp
a = sp.Popen(['echo hello world this is so great'], stdout=sp.PIPE, bufsize=0, 
             shell=True)
print(a.stdout.seekable())
print(a.stdout)
import numpy as np
np.fromfile(a.stdout, dtype='uint8', count=10)
False
<_io.FileIO name=12 mode='rb' closefd=True>
array([104, 101, 108, 108, 111,  32, 119, 111, 114, 108], dtype=uint8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions