[issue43069] Python fails to read a script whose path is `/dev/fd/X`

2021-01-30 Thread Alexey Izbyshev


Alexey Izbyshev  added the comment:

I would suggest to start digging from the following piece of code in 
`maybe_pyc_file()` (Python/pythonrun.c):

 int ispyc = 0;
 if (ftell(fp) == 0) {
 if (fread(buf, 1, 2, fp) == 2 &&
 ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic)
 ispyc = 1;
 rewind(fp);
 }

--
nosy: +izbyshev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43069] Python fails to read a script whose path is `/dev/fd/X`

2021-01-30 Thread Ronald Oussoren


Ronald Oussoren  added the comment:

I can reproduce the issue on macOS 11.1. 

As you write:
- running /dev/fd/X as a script fails silently if it refers to an smallish file
- reading /dev/fd/X referring to the same smallish files works fine (the 
``open('/dev/fd/9').read()`` scenario. 

If I read the code in Modules/main.c correctly the main difference between the 
two scenario's is that the first scenario using the C stdio library to read the 
file (in pymain_run_file_obj), and the latter uses the normal Python io stack.

Reading /dev/fd/9 works fine when using either stdio or open/read in C code. 

I have not yet tried to untangle the layers of C code from pymain_run_file_obj 
to actually reading the script, there might be something there that sheds light 
on what's going on here.

I'm not yet willing to claim this is an OS bug as I've failed to reproduce this 
outside of Python.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43069] Python fails to read a script whose path is `/dev/fd/X`

2021-01-29 Thread Ciprian Dorin Craciun


New submission from Ciprian Dorin Craciun :

Sometimes (especially from wrapper scripts) one would like to call Python with 
a script that should be read from a file-descriptor, like `python3 /dev/fd/9`;  
most likely the backing is a file in `TMPDIR` (perhaps unlinked, like `bash`'s 
"here documents").

However on OSX (I've tried it on `10.15.7` and `10.13.6`), for some reason if 
that script is too "large" (more than a couple of characters) it just bails 
out, even if that file-descriptor is in fact backed by a file.

For example:

echo 'print("1234567890")' >/tmp/x.py && python3 /dev/fd/9 9/tmp/x.py && python3 /dev/fd/9 9

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com