Unitech / Unitech/pm2

Running child_process (spawn) through pm2 does not work

Open
#5,526 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

I am running a script written in Javascript through PM2. In that script I am also calling a Python script to do something. The script works just fine running it through VS Code, however running it through PM2 gives me the following error:

Error: spawn python ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn python',
  path: 'python',
  spawnargs: [ 'pywinauto_login.py' ]
}

My child_process looks like this:

  // Python child process
  const python = spawn('python', [`pywinauto_login.py`], {cwd: 'C:\\Users\\kitt\\Documents\\ck\\'});
  python.on('close', (code) => {
    console.log('code');
  });

My working directory is:
C:\Users\kitt\Documents\ck\

And the script im trying to run as a child process is found at: C:\\Users\\kitt\\Documents\\ck\\pywinauto_login.py

Supporting information

I've tried countless ways to make it work, and tried a ton of different ways to define the path, and they all work when run from the terminal or in vscode, but not with PM2

Also tried running everything as admin.

$ pm2 report

--- Daemon logs --------------------------------------------
C:\Users\kitt\.pm2\pm2.log last 20 lines:
PM2        | 2023-01-17T14:30:56: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-17T14:30:56: PM2 error: Error: No matching pid found
PM2        | 2023-01-17T14:31:03: PM2 log: Stopping app:index id:0
PM2        | 2023-01-17T14:31:03: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:31:03: PM2 log: pid=9432 msg=process killed
PM2        | 2023-01-17T14:39:41: PM2 log: Process 0 in a stopped status, starting it
PM2        | 2023-01-17T14:39:41: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:39:41: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:40:44: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:41:53: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2023-01-17T14:42:30: PM2 log: App [index:0] online
PM2        | 2023-01-17T14:42:35: PM2 log: Stopping app:index id:0
PM2        | 2023-01-17T14:42:37: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2023-01-17T14:42:37: PM2 log: pid=4152 msg=process killed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named; start by reproducing the child_process.spawn('python', ...) call under PM2 and compare its environment with VS Code or a terminal. Use the supplied pm2 report and logs to investigate the missing executable, and consider the issue resolved when the Python child starts through PM2 without ENOENT.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, python
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.