Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespacing doesn't work when using Popen in a runned pm2 #4778

Open
BarryThrill opened this issue Jul 12, 2020 · 13 comments
Open

Namespacing doesn't work when using Popen in a runned pm2 #4778

BarryThrill opened this issue Jul 12, 2020 · 13 comments

Comments

@BarryThrill
Copy link

BarryThrill commented Jul 12, 2020

What's going wrong?

Hello guys!

I have worked abit with name spacing and I have realized that if you try to do a namespacing inside a script that is runned by pm2 and Popen etc:

Popen(f"pm2 start test.py --name test1 --namespace testing --interpreter=python3", shell=True).communicate()

That will not create a namespace for the name testing.

How could we reproduce this issue?

test_new.py - Run this FIRST with pm2 start test_new.py --interpreter=python3

from subprocess import Popen

Popen(f"pm2 start test.py --name test1 --namespace testing --interpreter=python3", shell=True).communicate()

test.py

print("hello world!")

What should happend is that test.py should have the name = test and namespace = testing but it says default instead.

Excepted result:

--- PM2 report ----------------------------------------------------------------
Date                 : Sun Jul 12 2020 15:09:14 GMT+0200 (GMT+02:00)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.4.1
node version         : 12.18.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : autosnkr
uid                  : 1000
gid                  : 1000
uptime               : 17535min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.4.1
node version         : 12.18.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : autosnkr
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i7-8700T CPU @ 2.40GHz
cpus nb              : 12
freemem              : 9361747968
totalmem             : 16616714240
home                 : /home/autosnkr
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                              │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 297 │ test		  	          │ default     │ N/A     │ fork    │ 5234     │ 10m    │ 3    │ online    │ 0%       │ 13.5mb   │ autosnkr │ disabled │
└─────┴───────────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list running is not in sync with saved list. aplace hoopz paulfriends solestory streetlab differs. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
/home/autosnkr/.pm2/pm2.log last 20 lines:
PM2        | 2020-07-12T14:58:47: PM2 log: App [test:297] starting in -fork mode-
PM2        | 2020-07-12T14:58:47: PM2 log: App [test:297] online

Supporting information

I love you guys for what you guys have done <3

@ghost
Copy link

ghost commented Jul 23, 2020

@sbleon Hey there! Has the bug been fixed? :)

@sbleon
Copy link
Contributor

sbleon commented Jul 23, 2020

Hi, Barry. I submitted a pull request with a change that I think will fix your issue. It hasn't been merged yet, though, so if you want to try out the bug fix now I suggest that you fork my fork and use your copy of my fix-namespace-cli-option branch.

@BarryThrill
Copy link
Author

BarryThrill commented Jul 24, 2020

Hi @sbleon After testing your branch it seems like it is still given wrong namespace afterall.

What I did is that I started a script called test.py (namespace = hello) which I started with pm2. Inside the test.py I call:

Popen("pm2 start /home/test/git/test/AIO_WF/monitoring.py --name test--namespace test--interpreter=python3 --no-autorestart")

What should happend is that namespace here should have the name test but instead its using the namespace hello from previous test.py.

I expected when I give a namespace in Popen then it should use that namespace which in my example is "test" but instead it used from the previous script which has the namespace "hello".

Example:
Inside the manualUrlRegistering we call:

Popen("pm2 start /home/test/git/test/AIO_WF/junkyard.py --name junkyard_585 --namespace junkyard --interpreter=python3 --no-autorestart")

Excepted result:
name: junkyard_585 - namespace: junkyard

Actual result:
image

@sbleon
Copy link
Contributor

sbleon commented Jul 24, 2020 via email

@BarryThrill
Copy link
Author

instead its using the namespace hello from previous test.py. I think that namespaces maybe only get detected when first starting a process. If you want to change the namespace, you may have to delete and then start the process anew.

Hi there again MR.@sbleon! I have re-edit my question and I agree with what you say!

However I do still think it is a bug with the namespaces because what I basically do is that I start a pm2 script that calls another script with pm2 pm2 start /home/test/git/test/AIO_WF/junkyard.py --name junkyard_585 --namespace junkyard --interpreter=python3 --no-autorestart which logically should just create a new PM2 process with the given namespace. But instead it is just ignoring the namespace for the second script which I don't see the reason why it wouldn't in this case :(

As you mentioned. I do believe it takes the namespace from the first starting process. For me it would be much more needed if I would be able to have the namespace that I have given when starting another pm2 process inside a pm2 process that is already running. To easier navigate my scripts. If that makes sense?

@sbleon
Copy link
Contributor

sbleon commented Jul 27, 2020 via email

@BarryThrill
Copy link
Author

I agree that the namespace behavior still isn't ideal, even with my patch. My patch only addresses the first start of a given process. I think that subsequent starts with a different namespace should spawn new processes. Do you agree with that?

On Fri, Jul 24, 2020 at 11:24 AM BarryThrill @.> wrote: instead its using the namespace hello from previous test.py. I think that namespaces maybe only get detected when first starting a process. If you want to change the namespace, you may have to delete and then start the process anew. Hi there again @. https://github.com/sbleon! I have re-edit my question and I agree with what you say! However I do still think it is a bug with the namespaces because what I basically do is that I start a pm2 script that calls another script with pm2 pm2 start /home/test/git/test/AIO_WF/junkyard.py --name junkyard_585 --namespace junkyard --interpreter=python3 --no-autorestart which logically should just create a new PM2 process with the given namespace. But instead it is just ignoring the namespace for the second script which I don't see the reason why it wouldn't in this case :( As you mentioned. I do believe it takes the namespace from the first starting process. For me it would be much more needed if I would be able to have the namespace that I have given when starting another pm2 process inside a pm2 process that is already running. To easier navigate my scripts. If that makes sense? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#4778 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQQN5QFBPI6RG2WWJGED3R5GRUNANCNFSM4OXZQJPA .

I would say yes. As it is a new pm2 process with a new namespace and new name it should spawn a new process of that instance. As you mentioned. Your patch only addresses the first start of given process. It should start instead of a new process with given namespace. 😁

@Unitech
Copy link
Owner

Unitech commented Sep 29, 2020

published in pm2@4.5.0

npm install pm2@latest -g

@sbleon
Copy link
Contributor

sbleon commented Sep 29, 2020 via email

@Unitech
Copy link
Owner

Unitech commented Sep 29, 2020

Thanks for the contributions!

@BarryThrill
Copy link
Author

The issue still remains randomly, where it randomly uses the default even thought I have in a script given a namespace like I have given in the start of the thread.

@youxiaohou
Copy link

youxiaohou commented Jan 28, 2023

This issue still exists in version 5.2.2

@ramiroaisen
Copy link

This issue still exists in version 5.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants