[issue35306] OSError [WinError 123] when testing if pathlib.Path('*') (asterisks) exists

2018-11-23 Thread jimbo1qaz_ via Gmail


New submission from jimbo1qaz_ via Gmail :

I'm writing a program taking paths from user input through CLI.

`path` is a pathlib.Path().

Since Windows doesn't expand asterisks, I check if the path doesn't exist. If 
so I expand using Path().glob(path).

Unfortunately on Windows, if `path` (type: Path) contains asterisks, checking 
`path.exists()` or `path.is_dir()` raises WinError 123.

Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: 
Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> Path('*').exists()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1318, 
in exists
self.stat()
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, 
in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is 
incorrect: '*'
>>> Path('*').is_dir()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1330, 
in is_dir
return S_ISDIR(self.stat().st_mode)
  File "C:\Users\jimbo1qaz\Miniconda3\envs\python37\lib\pathlib.py", line 1140, 
in stat
return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label syntax is 
incorrect: '*'

I also reproduced on Miniconda 3.6.6, 3.7.0, and official Python 3.7.1.

According to https://bugs.python.org/issue29827 , os.path.exists() (not 
Path.exists() ) returns False on any OSError.

-

On Linux, checking paths with null bytes (a less common occurrence) raises a 
different error:

>>> import pathlib
>>> pathlib.Path("\x00").exists()
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.6/pathlib.py", line 1336, in exists
self.stat()
  File "/usr/lib/python3.6/pathlib.py", line 1158, in stat
return self._accessor.stat(self)
  File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
return strfunc(str(pathobj), *args)
ValueError: embedded null byte

--
components: Library (Lib)
messages: 330371
nosy: jimbo1qaz_
priority: normal
severity: normal
status: open
title: OSError [WinError 123] when testing if pathlib.Path('*') (asterisks) 
exists
versions: Python 3.6, Python 3.7

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



[issue35306] OSError [WinError 123] when testing if pathlib.Path('*') (asterisks) exists

2019-01-06 Thread jimbo1qaz_ via Gmail


jimbo1qaz_ via Gmail  added the comment:

Should Path.resolve() also avoid raising OSError?

Path('*').resolve()

Traceback (most recent call last):
...truncated
  File "", line 1, in 
Path('*').resolve()
  File 
"C:\Users\jimbo1qaz\AppData\Local\Programs\Python\Python37\lib\pathlib.py", 
line 1134, in resolve
s = self._flavour.resolve(self, strict=strict)
  File 
"C:\Users\jimbo1qaz\AppData\Local\Programs\Python\Python37\lib\pathlib.py", 
line 192, in resolve
s = self._ext_to_normal(_getfinalpathname(s))
OSError: [WinError 123] The filename, directory name, or volume label syntax is 
incorrect: '*'


os.path.realpath('"*')
Out[8]: 'C:\\Users\\jimbo1qaz\\Dropbox\\encrypted\\code\\corrscope\\"*'
os.path.abspath('*"')
Out[13]: 'C:\\Users\\jimbo1qaz\\Dropbox\\encrypted\\code\\corrscope\\*"'

(sidenote: what os.path operation does Path.resolve() match? 
Path('nonexistent').resolve() returns a relative path on Python 3.7.1, whereas 
Path().resolve() returns an absolute path.)

--

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



[issue35754] When writing/closing a closed Popen.stdin, I get OSError vs. BrokenPipeError randomly or depending on bufsize

2019-01-16 Thread jimbo1qaz_ via Gmail


New submission from jimbo1qaz_ via Gmail :

Windows 10 1709 x64, Python 3.7.1.

Minimal example and stack traces at 
https://gist.github.com/jimbo1qaz/75d7a40cac307f8239ce011fd90c86bf

Essentially I create a subprocess.Popen, using a process (msys2 head.exe) which 
closes its stdin after some amount of input, then write nothing but b"\n"*1000 
bytes to its stdin.

If the bufsize is small (1000 bytes), I always get OSError: [Errno 22] Invalid 
argument

If the bufsize is large (1 million bytes), I always get BrokenPipeError: [Errno 
32] Broken pipe. (This happens whether I write 1 million newlines or 1000 at a 
time).

Originally I created a ffmpeg->ffplay pipeline with a massive bufsize (around 
1280*720*3 * 2 frames), then wrote 1280*720*3 bytes of video frames at a time. 
Closing ffplay's window usually created BrokenPipeError, but occasionally 
OSError. This was actually random.




It seems that this is known to some extent, although I couldn't find any 
relevant issues on the bug tracker, and "having to catch 2 separate errors" 
isn't explained on the documentation. (Is it intended though undocumented 
behavior?)

Popen._communicate() calls Popen._stdin_write(), but specifically ignores 
BrokenPipeError and OSError where exc.errno == errno.EINVAL == 22 (the 2 cases 
I encountered).

But I don't call Popen.communicate() but instead write directly to stdin, since 
I have a loop that outputs 1 video frame at a time, and rely on pipe blocking 
to stop my application from running too far ahead of ffmpeg/ffplay.



popen.stdin is a <_io.BufferedWriter name=3>.

https://docs.python.org/3/library/io.html#io.BufferedIOBase.write

>Write the given bytes-like object, b, and return the number of bytes written 
>(always equal to the length of b in bytes, since if the write fails an OSError 
>will be raised). Depending on the actual implementation, these bytes may be 
>readily written to the underlying stream, or held in a buffer for performance 
>and latency reasons.

The page doesn't mention BrokenPipeError at all (Ctrl+F). So why do I 
*sometimes* get a BrokenPipeError (subclasses ConnectionError subclasses 
OSError) instead?

--
messages: 333792
nosy: jimbo1qaz_
priority: normal
severity: normal
status: open
title: When writing/closing a closed Popen.stdin, I get OSError vs. 
BrokenPipeError randomly or depending on bufsize
versions: Python 3.7

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



[issue35754] When writing/closing a closed Popen.stdin, I get OSError vs. BrokenPipeError randomly or depending on bufsize

2019-01-16 Thread jimbo1qaz_ via Gmail


jimbo1qaz_ via Gmail  added the comment:

Popen._stdin_write() has comments linking to https://bugs.python.org/issue19612 
and https://bugs.python.org/issue30418 .

--

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