Eryk Sun added the comment:

spawnl is implemented by calling _spawnv [1], which is documented to invoke the 
invalid parameter handler if argv points to a NULL pointer. It wants the 
program name, or whatever, as long as argv[0] isn't NULL or an empty string, 
e.g. `os.spawnl(os.P_NOWAIT, 'C:/Tcl/bin/tclsh.exe', 'tclsh')`. 

The invalid parameter handler should be disabled (_Py_BEGIN_SUPPRESS_IPH) when 
calling _spawnv[e], which in this case would lead to an EINVAL OSError instead 
of crashing the process. 

For example:

    import os, sys
    from ctypes import *

    ucrt = CDLL('ucrtbase')

    @CFUNCTYPE(None, c_wchar_p, c_wchar_p, c_wchar_p, c_int, c_void_p)
    def iph(*args):
        pass

    ucrt._set_thread_local_invalid_parameter_handler(iph)

    >>> os.spawnl(os.P_NOWAIT, sys.executable)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python35\lib\os.py", line 977, in spawnl
        return spawnv(mode, file, args)
    OSError: [Errno 22] Invalid argument

Also, in this case a descriptive ValueError would be friendlier, given an empty 
argv or argv[0] that's an empty string -- at least on Windows.

[1]: https://msdn.microsoft.com/en-us/library/7zt1y878.aspx

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28732>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to