Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33536 > unrolled thread
| Started by | andrea crotti <andrea.crotti.0@gmail.com> |
|---|---|
| First post | 2012-11-19 10:39 +0000 |
| Last post | 2012-11-19 21:30 -0800 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
changing process name andrea crotti <andrea.crotti.0@gmail.com> - 2012-11-19 10:39 +0000
Re: changing process name Tim Roberts <timr@probo.com> - 2012-11-19 21:30 -0800
| From | andrea crotti <andrea.crotti.0@gmail.com> |
|---|---|
| Date | 2012-11-19 10:39 +0000 |
| Subject | changing process name |
| Message-ID | <mailman.1.1353321572.29569.python-list@python.org> |
I have very long processes to spawn which I want to lauch as separate
processes (and communicate with ZeroMQ), but now the problem is that the
forked process appears in "ps" with the same name as the launcher
process.
This is a simplified version of what I'm trying to do:
import sys
from os import fork, _exit
def on_forked_process(func):
"""Decorator that forks the process, runs the function and gives
back control to the main process
"""
def _on_forked_process(*args, **kwargs):
pid = fork()
if pid == 0:
func(*args, **kwargs)
_exit(0)
else:
return pid
return _on_forked_process
@on_forked_process
def start_long_proc():
sys.argv[:] = [sys.argv[0]] + ['daemon', 'arguments']
from daemon import long_sleep
long_sleep()
if __name__ == '__main__':
start_long_proc()
# if the main process is still running but it's not told the child
# when it dies then it becomes a zombie?? no apparently it doesn't
while True:
pass
Where daemon.py:
import sys
import time
def long_sleep():
sys.argv[:] = [sys.argv[0]] + ['daemon', 'arguments']
time.sleep(20)
so both the sys.argv reassignment don't work so far, any other way to
fix this?
On the real machine I also get zombie processes, but on my machine I
can't reproduce this, and would also be nice to fix that..
Thanks
[toc] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2012-11-19 21:30 -0800 |
| Message-ID | <tb5ma85j71bdhsd6pdqorf4eselgn5s9jf@4ax.com> |
| In reply to | #33536 |
andrea crotti <andrea.crotti.0@gmail.com> wrote: >I have very long processes to spawn which I want to lauch as separate >processes (and communicate with ZeroMQ), but now the problem is that the >forked process appears in "ps" with the same name as the launcher >process. http://code.google.com/p/py-setproctitle/ -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web