【问题标题】:How to start a node server from a python shell command?如何从 python shell 命令启动节点服务器?
【发布时间】:2020-05-09 16:47:41
【问题描述】:

我在从 Python 启动节点服务器时遇到问题。我试着这样称呼它:

    os.system("nohup node /opt/solvoerp/solvo-erp/w_sender/app.js")

但我收到以下错误

(node:83046) UnhandledPromiseRejectionWarning: Error: Page crashed!
(node:83046) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:83046) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

如果我从 shell 执行命令,节点服务器会正​​确执行,可能是 shell 问题。

【问题讨论】:

  • 节点应用程序是否运行?您附加了一些警告,但从文本中,它寻求节点应用程序 not 因错误而终止。还有一个问题——这个代码是更大的 Python 程序/应用程序的一部分吗?当你打开一个 python shell,import os,然后运行这个语句会发生什么?
  • 另外,请注意,从 shell 运行的环境可能与 Python 代码维护的环境不同。最后,使用os.system 通常是调用外部进程的错误方式。标准库的subprocess 模块有许多您可以(并且应该)用于此目的的函数和对象。
  • @Roy2012 是的,它是一个更大的 python 程序的一部分,它从环境中看到了错误。
  • @AmitaIrron 与子进程有相同的错误。谢谢,我会尝试调试环境导致错误的原因

标签: python node.js shell nohup


【解决方案1】:

看来是在 os.system 或子进程结束调用进程后节点服务器关闭,所以我使用 pm2 像这样对节点服务器进行守护:

from subprocess import call,check_call

check_call(['pm2', 'start', 'node /opt/solvoerp/solvo-erp/w_sender/app.js'])

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 2017-01-30
    • 1970-01-01
    • 2015-06-28
    相关资源
    最近更新 更多