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

    <tfoot id='f6CsY'></tfoot>

      1. <small id='f6CsY'></small><noframes id='f6CsY'>

          <bdo id='f6CsY'></bdo><ul id='f6CsY'></ul>
      2. Python 作为 Windows 服务运行:OSError: [WinError 6] 句柄无效

        Python running as Windows Service: OSError: [WinError 6] The handle is invalid(Python 作为 Windows 服务运行:OSError: [WinError 6] 句柄无效)
      3. <i id='7m35X'><tr id='7m35X'><dt id='7m35X'><q id='7m35X'><span id='7m35X'><b id='7m35X'><form id='7m35X'><ins id='7m35X'></ins><ul id='7m35X'></ul><sub id='7m35X'></sub></form><legend id='7m35X'></legend><bdo id='7m35X'><pre id='7m35X'><center id='7m35X'></center></pre></bdo></b><th id='7m35X'></th></span></q></dt></tr></i><div id='7m35X'><tfoot id='7m35X'></tfoot><dl id='7m35X'><fieldset id='7m35X'></fieldset></dl></div>

          • <tfoot id='7m35X'></tfoot>

              <bdo id='7m35X'></bdo><ul id='7m35X'></ul>
              <legend id='7m35X'><style id='7m35X'><dir id='7m35X'><q id='7m35X'></q></dir></style></legend>
            • <small id='7m35X'></small><noframes id='7m35X'>

                  <tbody id='7m35X'></tbody>
                • 本文介绍了Python 作为 Windows 服务运行:OSError: [WinError 6] 句柄无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 Python 脚本,它作为 Windows 服务运行.该脚本通过以下方式分叉另一个进程:

                  I have a Python script, which is running as a Windows Service. The script forks another process with:

                  with subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as proc:
                  

                  导致以下错误:

                  OSError: [WinError 6] The handle is invalid
                     File "C:Program Files (x86)Python35-32libsubprocess.py", line 911, in __init__
                     File "C:Program Files (x86)Python35-32libsubprocess.py", line 1117, in _get_handles
                  

                  推荐答案

                  subprocess.py 中的第 1117 行是:

                  Line 1117 in subprocess.py is:

                  p2cread = _winapi.GetStdHandle(_winapi.STD_INPUT_HANDLE)
                  

                  这让我怀疑服务进程没有与之关联的 STDIN (TBC)

                  which made me suspect that service processes do not have a STDIN associated with them (TBC)

                  可以通过将文件或空设备作为标准输入参数提供给 popen 来避免这种麻烦的代码.

                  This troublesome code can be avoided by supplying a file or null device as the stdin argument to popen.

                  Python 3.x 中,您可以简单地传递 stdin=subprocess.DEVNULL.例如

                  In Python 3.x, you can simply pass stdin=subprocess.DEVNULL. E.g.

                  subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL)
                  

                  Python 2.x 中,您需要将文件处理程序设为 null,然后将其传递给 popen:

                  In Python 2.x, you need to get a filehandler to null, then pass that to popen:

                  devnull = open(os.devnull, 'wb')
                  subprocess.Popen( args=[self.exec_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=devnull)
                  

                  这篇关于Python 作为 Windows 服务运行:OSError: [WinError 6] 句柄无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)

                • <small id='RFdQq'></small><noframes id='RFdQq'>

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