1. <tfoot id='Iz5he'></tfoot>
      <bdo id='Iz5he'></bdo><ul id='Iz5he'></ul>
    <i id='Iz5he'><tr id='Iz5he'><dt id='Iz5he'><q id='Iz5he'><span id='Iz5he'><b id='Iz5he'><form id='Iz5he'><ins id='Iz5he'></ins><ul id='Iz5he'></ul><sub id='Iz5he'></sub></form><legend id='Iz5he'></legend><bdo id='Iz5he'><pre id='Iz5he'><center id='Iz5he'></center></pre></bdo></b><th id='Iz5he'></th></span></q></dt></tr></i><div id='Iz5he'><tfoot id='Iz5he'></tfoot><dl id='Iz5he'><fieldset id='Iz5he'></fieldset></dl></div>
  2. <small id='Iz5he'></small><noframes id='Iz5he'>

  3. <legend id='Iz5he'><style id='Iz5he'><dir id='Iz5he'><q id='Iz5he'></q></dir></style></legend>

    1. OSError:[Errno 22] 子进程中的参数无效

      时间:2023-09-02

        <small id='M1iWl'></small><noframes id='M1iWl'>

            <tbody id='M1iWl'></tbody>
        1. <tfoot id='M1iWl'></tfoot>
        2. <legend id='M1iWl'><style id='M1iWl'><dir id='M1iWl'><q id='M1iWl'></q></dir></style></legend>
          <i id='M1iWl'><tr id='M1iWl'><dt id='M1iWl'><q id='M1iWl'><span id='M1iWl'><b id='M1iWl'><form id='M1iWl'><ins id='M1iWl'></ins><ul id='M1iWl'></ul><sub id='M1iWl'></sub></form><legend id='M1iWl'></legend><bdo id='M1iWl'><pre id='M1iWl'><center id='M1iWl'></center></pre></bdo></b><th id='M1iWl'></th></span></q></dt></tr></i><div id='M1iWl'><tfoot id='M1iWl'></tfoot><dl id='M1iWl'><fieldset id='M1iWl'></fieldset></dl></div>
            • <bdo id='M1iWl'></bdo><ul id='M1iWl'></ul>

              • 本文介绍了OSError:[Errno 22] 子进程中的参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Python 3.3.3视窗 7

                Python 3.3.3 Windows 7

                Here is the full stack:
                Traceback (most recent call last):
                  File "BlahMyScript.py", line 578, in Call
                    output = process.communicate( input=SPACE_KEY, timeout=600 )
                  File "C:Python33libsubprocess.py", line 928, in communicate
                    stdout, stderr = self._communicate(input, endtime, timeout)
                  File "C:Python33libsubprocess.py", line 1202, in _communicate
                    self.stdin.write(input)
                OSError: [Errno 22] Invalid argument
                

                代码如下所示:

                process = subprocess.Popen( arguments,
                                stdin=subprocess.PIPE,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                universal_newlines=True,
                                env=environment )
                
                output = process.communicate( input=SPACE_KEY, timeout=600 )
                

                此代码每天运行数百次而没有问题.但是,如果在同一台机器上运行多个脚本(相同的脚本,但有时来自不同的文件夹),我会收到错误消息.脚本未执行相同的操作(即:当我收到此错误时,另一个脚本未执行子进程).

                This code runs hundreds of times a day without problems. But if more than one script is running on the same machine (the same script, but sometimes from different folders) I get the error. The scripts are not executing the same thing (i.e.: the other script is not executing a subprocess when I get this error).

                subProcess 代码使用许多不同的命令行来引发错误.

                The subProcess code raises the error with many different command lines fed to it.

                那么,有人知道发生了什么吗?解释器是否存在多次执行(在不同进程中)的问题?通常工作得很好的相同代码,如果解释器运行相同(或非常相似)的脚本,就会出错.但他们通常执行脚本的不同部分.

                So, anyone has an idea as to what is happening? Does the interpreter have a problem with multiple execution (in different processes)? Same code that normally works perfectly fine, craps out if the interpreter is running the same (or very similar) scripts. But they are usually executing different parts of the script.

                我不知所措:在 8 核机器上使用单个处理器很烦人.

                I'm at a loss: Using a single processor on an 8 core machine is annoying.

                推荐答案

                以前communicate在写入进程stdinEPIPE错误>.从 3.3.5 开始,根据 issue 19612,它还会忽略 EINVAL (22) 如果子进程已经退出(参见 Lib/subprocess.py 第 1199 行).

                Previously communicate only ignored an EPIPE error when writing to the process stdin. Starting with 3.3.5, per issue 19612, it also ignores EINVAL (22) if the child has already exited (see Lib/subprocess.py line 1199).

                背景:

                process.communiciate 调用 process.stdin.write,它调用 io.FileIO.write,它在 Windows 上调用 C 运行时 _write,它调用 Win32 WriteFile(在本例中称为 NtWriteFile,作为 IRP_MJ_WRITEFastIoWrite 分派到 NamedPipe 文件系统.

                process.communiciate calls process.stdin.write, which calls io.FileIO.write, which on Windows calls the C runtime _write, which calls Win32 WriteFile (which in this case calls NtWriteFile, which dispatches to the NamedPipe filesystem, as either an IRP_MJ_WRITE or FastIoWrite).

                如果后者失败,它会设置一个 Windows 系统错误代码在线程中.在这种情况下,潜在的 Windows 错误可能是 ERROR_NO_DATA (232) 因为子进程已经退出.C 运行时将其映射到 EINVAL (22) 的 errno 值.然后由于 _write 失败,FileIO.write 根据 errno 的当前值引发 OSError.

                If the latter fails, it sets a Windows system error code in the thread. In this case the underlying Windows error is probably ERROR_NO_DATA (232) because the child process has already exited. The C runtime maps this to an errno value of EINVAL (22). Then since _write failed, FileIO.write raises OSError based on the current value of errno.

                附录:

                如果 CRT 将 ERROR_NO_DATA 映射到 EPIPE,则根本不会出现问题.Python 自己的 Windows 错误翻译通常遵循 CRT 的,但根据 issue 13063,它对映射 ERROR_NO_DATAEPIPE (32).因此,如果孩子已经退出,_winapi.WriteFile 会引发 BrokenPipeError.

                There wouldn't have been a problem at all if the CRT instead mapped ERROR_NO_DATA to EPIPE. Python's own Windows error translation generally follows the CRT's, but per issue 13063, it makes an exception to map ERROR_NO_DATA to EPIPE (32). Thus if the child has already exited, _winapi.WriteFile raises BrokenPipeError.

                在子进程已经退出的情况下,以下示例复制了 EINVAL 错误.它还显示了 _winapi.WriteFile(3.3.3 源链接)会将此错误映射到 EPIPE.IMO,这应该被认为是微软 CRT 中的一个错误.

                The following example replicates the EINVAL error given the child process has already exited. It also shows how _winapi.WriteFile (3.3.3 source link) would instead map this error to EPIPE. IMO, this should be considered a bug in Microsoft's CRT.

                >>> cmd = 'reg query hkcu'                                                
                >>> process = Popen(cmd, stdin=PIPE, stdout=PIPE, universal_newlines=True)
                >>> process.stdin.write(' ')
                Traceback (most recent call last):
                  File "<stdin>", line 1, in <module>
                OSError: [Errno 22] Invalid argument
                
                >>> hstdin = msvcrt.get_osfhandle(process.stdin.fileno())
                >>> _winapi.WriteFile(hstdin, b' ')                                       
                Traceback (most recent call last):
                  File "<stdin>", line 1, in <module>
                BrokenPipeError: [WinError 232] The pipe is being closed
                

                这篇关于OSError:[Errno 22] 子进程中的参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:终止子进程后终端文本变得不可见 下一篇:具有池/队列的Python多个子进程在一个完成后立即恢复输出并在队列中启动下一个作业

                相关文章

                1. <legend id='6lUff'><style id='6lUff'><dir id='6lUff'><q id='6lUff'></q></dir></style></legend>
                2. <tfoot id='6lUff'></tfoot>

                    <small id='6lUff'></small><noframes id='6lUff'>

                      <bdo id='6lUff'></bdo><ul id='6lUff'></ul>
                    <i id='6lUff'><tr id='6lUff'><dt id='6lUff'><q id='6lUff'><span id='6lUff'><b id='6lUff'><form id='6lUff'><ins id='6lUff'></ins><ul id='6lUff'></ul><sub id='6lUff'></sub></form><legend id='6lUff'></legend><bdo id='6lUff'><pre id='6lUff'><center id='6lUff'></center></pre></bdo></b><th id='6lUff'></th></span></q></dt></tr></i><div id='6lUff'><tfoot id='6lUff'></tfoot><dl id='6lUff'><fieldset id='6lUff'></fieldset></dl></div>