1748261 Members
3819 Online
108760 Solutions
New Discussion юеВ

Re: python

 
SOLVED
Go to solution
John Tannahill
Frequent Advisor

python

Is there a safe way in Python for a child to issue a logout that logs itself and its parent out (i.e., no child zombie process left behind)? When a process wants to log out, I want to do some general cleanup, etc. first in a child process and then log out both of them.

Thanks,
John
6 REPLIES 6
Jan van den Ende
Honored Contributor

Re: python

John,

in VMS, if a master process gets deleted, ALL its subprocesses (and subprocesses thereoff) are removed first. So, if a subprocess ("child" in Unix speak) stops its master PID process 9the "child" "kills" its "(great-)parent" ), it is IMPOSSIBLE to leave zombies.
That is mainly, because in VMS processes are not "killed", but they get (a rather severe) request to commit suicide. And as long as the process can do ANYTHING at all (and the requester has the rights to request it) the target process CLEANS UP and EXITs.

(but if you are talking Detached Processes, THAT is quite another story).

hth

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
John Tannahill
Frequent Advisor

Re: python

I also have tried the following in the "child":
ppid = os.getppid()
os.kill(ppid, signal.SIGKILL)
and I get a "function not implemented" - OpenVMS v7.3-2?

Is there another way to accomplish this in OpenVMS (my OpenVMS knowledge is quite limited)? Something like this seems like it would vaporize the parent, and then hopefully the child would not a problem?

John

Craig A Berry
Honored Contributor

Re: python

John,

This is not so much an OpenVMS question as a Python for OpenVMS question. There are various ways to kill processes on VMS and various ways to ask them to kill themselves, but in a dynamic scripting language like Python, you're really at the mercy of the language implementation, which in turn may be at the mercy of the C run-time or other infrastructure.

In your example, do we know which function is not implemented? Is it getppid or kill? I would suggest looking at the source of Python for OpenVMS and/or using whatever debugging capabilities Python has to see what those lines of Python translate to in terms of calls to the C library, etc.

I would also suggest rethinking your architecture and seeing whether the parent can clean up the children rather than the other way around, but we don't have enough information to know how feasible that is.

And finally (but probably the first thing you should do), consider posting to the Python for OpenVMS forum, where more specific expertise is likely available:

http://www.pi-net.dyndns.org/piforum/viewforum.php?f=4
Jean-Fran├зois Pi├йronne
Trusted Contributor
Solution

Re: python

John,

Python os.getppid and os.kill are just jacket routines to the corresponding C routine.

This is a VMS 7.3-2 problem which doesn't implement completely os.kill
The complete error return by os.kill is
OSError: [Errno 81] function not implemented

You can use the vms.starlet.delprc routines to kill the parent process and all it's subprocesses:
import os, vms.starlet
ppid = os.getppid()
vms.starlet.delprc(ppid)

As mentioned this only work if you use subprocesses and not detached processes.

Craig: Why a forum named OpenVMS, language and scripting whould be a incorrect place to post a question on Python on OpenVMS (which is a scripting language on OpenVMS...)? There is much more readers of the ITRC forum than on the Python for OpenVMS forum...


JF
Jan van den Ende
Honored Contributor

Re: python

John,

I know nothing about Python, (but i know Jean-Fran├Г┬зois is an expert), but does Python have the capability to SPAWN (like many other such products; under whatever name it is implemented) some native OS routine?

In that case, you can just SPAWN a little DCL that gets the master PID and stops it.

In quite other contexts, we do this (with a delay) for all batch procedures that sometimes exhibit indefinite waits to cause problems.
(eg, BACKUP to tapes behind a tape robot. We dislike a day without backup, but we HATE the various afterprocessings not being done!)

fwiw,

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
John Tannahill
Frequent Advisor

Re: python

JF's solution worked! Thanks!