Pyinstaller子进程异常在窗口模式下运行

时间:2018-03-08 17:58:28

标签: python django python-3.x pyinstaller

我正在使用pyinstaller来创建我的应用程序。在我的django应用程序中,我正在使用子进程。当我在noconsole模式下执行pyinstaller时,它会抛出错误。 错误日志:

Traceback (most recent call last):
  File "site-packages\django\core\handlers\base.py", line 149, in get_response
  File "site-packages\django\core\handlers\base.py", line 147, in get_response
  File "crumbs_tableau\views.py", line 1603, in parser
  File "site-packages\django\shortcuts.py", line 67, in render
  File "site-packages\django\template\loader.py", line 96, in render_to_string
  File "site-packages\django\template\loader.py", line 43, in get_template
django.template.exceptions.TemplateDoesNotExist: helpers/error.html
Internal Server Error: /
Traceback (most recent call last):
  File "crumbs_tableau\views.py", line 286, in parser
  File "crumbs_tableau\views.py", line 248, in mac_list
  File "subprocess.py", line 336, in check_output
  File "subprocess.py", line 403, in run
  File "subprocess.py", line 667, in __init__
  File "subprocess.py", line 905, in _get_handles
  File "subprocess.py", line 955, in _make_inheritable
OSError: [WinError 6] The handle is invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "site-packages\django\core\handlers\base.py", line 149, in get_response
  File "site-packages\django\core\handlers\base.py", line 147, in get_response
  File "crumbs_tableau\views.py", line 1603, in parser
  File "site-packages\django\shortcuts.py", line 67, in render
  File "site-packages\django\template\loader.py", line 96, in render_to_string
  File "site-packages\django\template\loader.py", line 43, in get_template
django.template.exceptions.TemplateDoesNotExist: helpers/error.html
Not Found: /static/parser/bootstrap.css.map

1 个答案:

答案 0 :(得分:2)

在窗口模式下调用子进程时,需要定义stdin和stderr。 例如:

p = subprocess.Popen(["netstat", "-a", "-n", "-o"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL)

这是因为如果这些句柄未设置为空,则会尝试复制这些句柄。