在主管中使用时子进程失败

时间:2016-05-09 08:43:47

标签: python subprocess celery supervisord

我有芹菜任务:

subprocess.check_call([script.sh, 'clean'], cwd=module_folder, stdout=fd_log_out, stderr=fd_log_err)

当我从命令行运行worker时,一切正常。

当芹菜工人从主管那里开始时,我会在我的日志中得到这个:

[2016-05-09 10:31:30,129: ERROR/MainProcess] Task project_server.executions.tasks.execution_run[04e6295b-2aa4-4384-9218-fccb111a20df] raised unexpected: TypeError('expect bytes or str, not NoneType',)
Traceback (most recent call last):
  File "/home/benjamin/.virtualenvs/project/lib/python3.4/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/benjamin/.virtualenvs/project/lib/python3.4/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/benjamin/Project/projectserver/project_server/executions/tasks.py", line 88, in execution_run
    fd_log_err=fd_log_err)
  File "/home/benjamin/Project/projectcommon/project_common/generator/__init__.py", line 807, in create_application
    fd_log_out, fd_log_err)
  File "/home/benjamin/Project/projectcommon/project_common/models/extensions.py", line 550, in build_scala_module
    subprocess.check_call([script.sh, 'clean'], cwd=module_folder, stdout=fd_log_out, stderr=fd_log_err)
  File "/usr/lib/python3.4/subprocess.py", line 556, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.4/subprocess.py", line 537, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1381, in _execute_child
    executable = os.fsencode(executable)
  File "/home/benjamin/.virtualenvs/project/lib/python3.4/os.py", line 770, in fsencode
    raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
TypeError: expect bytes or str, not NoneType

为什么会失败?

2 个答案:

答案 0 :(得分:1)

好的,我明白了:script.sh不在主管给出的$ PATH中

答案 1 :(得分:0)

通过systemd运行python脚本包括WorkingDirectory到服务文件时修复相同的错误:

[Unit]
Description=Python script
After=multi-user.target

[Service]
WorkingDirectory=/path/to/script
User=user
Group=group

Type=idle
ExecStart=/path/to/python runner.py

[Install]
WantedBy=multi-user.target

如果您这样写(没有WorkingDirectory的脚本的完整路径)

ExecStart=/path/to/python /path/to/script/runner.py

你会有错误。