Is it technically possible to give Python option of naming process ofrunning script?

X

xliiv

Like the topic.. .
I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.
 
C

Chris Angelico

Like the topic.. .
I use Python a lot, both Windows and Linux, and it's little weird to have many python process without fast distinction which is what.

I've no idea if it's even possible on Windows. On Linux, what you want
is the prctl function, which (AFAIK) isn't directly available.

Google is your friend, though. Question's already been asked on Stack
Overflow and such, and has a few answers. Nothing that looks
cut-and-dried ready, but several that might work. Look for 'prctl' and
'PR_SET_NAME', which are the C-level function and constant that do the
job; a cursory examination of PyPI shows a module with prctl in the
name, so that may be of value.

ChrisA
 
G

Grant Edwards

I've no idea if it's even possible on Windows. On Linux, what you want
is the prctl function, which (AFAIK) isn't directly available.

Google is your friend, though. Question's already been asked on Stack
Overflow and such, and has a few answers. Nothing that looks
cut-and-dried ready, but several that might work.

The question of how to set the application name comes up somewhat
regularly. It would be awfully nice if there was a way for python
applications to set their application name. It's especially useful
for daemons, and makes it much easier when you can kill them by name
instead of having to look up the PID.

It seems like an excellent thing to add to the "os" module.
 
T

Terry Reedy

It seems like an excellent thing to add to the "os" module.

If 'prctl' is a standard POSIX system call, then it should be a
candidate for inclusion in the os module if someone opens a tracker
enhancement issue and presents an argument in favor.
 
P

Prasad, Ramit

It seems like an excellent thing to add to the "os" module.
If 'prctl' is a standard POSIX system call, then it should be a
candidate for inclusion in the os module if someone opens a tracker
enhancement issue and presents an argument in favor.


I think this request was already denied: http://bugs.python.org/issue5672

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
P

Prasad, Ramit

I think this request was already denied: http://bugs.python.org/issue5672

Also take a look at: https://github.com/dvarrazzo/py-setproctitle
Though since they just create a Named Object in Windows, I am not sure
it would work for something like killall.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston,TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
A

Alain Ketterlin

Terry Reedy said:
If 'prctl' is a standard POSIX system call, then it should be a
candidate for inclusion in the os module if someone opens a tracker
enhancement issue and presents an argument in favor.

It's not. The man page says "This call is Linux-specific."

-- Alain.
 
D

Dave Angel

Also take a look at: https://github.com/dvarrazzo/py-setproctitle
Though since they just create a Named Object in Windows, I am not sure
it would work for something like killall.

There is/was a project called exemaker for Windows. (see Pypi for
link). I don't use Windows any more, but it was a nice trick, when it
worked. Not all python scripts could be wrapped in it, but basically it
let you wrap a python script in a tiny Windows program which launched
the usual python dll's. You could call it anything you liked, and
that's what the task manager saw as the process name.
 
X

xliiv

Like the topic.. .
The question of how to set the application name comes up somewhat
regularly. It would be awfully nice if there was a way for python
applications to set their application name. It's especially useful
for daemons, and makes it much easier when you can kill them by name
instead of having to look up the PID.

It seems like an excellent thing to add to the "os" module.


I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?
 
X

xliiv

Like the topic.. .
The question of how to set the application name comes up somewhat
regularly. It would be awfully nice if there was a way for python
applications to set their application name. It's especially useful
for daemons, and makes it much easier when you can kill them by name
instead of having to look up the PID.

It seems like an excellent thing to add to the "os" module.


I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?
 
D

Dave Angel

I did google, I've played with Exemaker (it works perfect, but not py3) and i've seen questions on Stackoverflow.
The thing I mean is a build feature of python to give such a name. Not 3rd part or etc. like Grant Edwards said. Is it possible?

How about simply using cp to copy the python executable, run chmod +x on
it, and run that one? Then ps would list it as the new name, not as python.

i tried it on /usr/bin/python2.7 but I see no reason the same
approach won't work on 3.x Note, I copied it to a new name in the same
directory, which may be important. or not.
 
G

Grant Edwards

How about simply using cp to copy the python executable, run chmod +x on
it, and run that one? Then ps would list it as the new name, not as python.

That's rather a waste of memory. Better to use a link. That way the
executable can still be shared by multiple programs and won't be
duplicated in memory.
i tried it on /usr/bin/python2.7 but I see no reason the same
approach won't work on 3.x Note, I copied it to a new name in the same
directory, which may be important. or not.

Seems like an awfully obtuse way of doing things -- I don't really
want to have 15 different copies of Python (or even links), and it
requires root privleges every time you want to run a Python program
with the "correct" name.
 
D

Dave Angel

That's rather a waste of memory. Better to use a link. That way the
executable can still be shared by multiple programs and won't be
duplicated in memory.

Seems like an awfully obtuse way of doing things -- I don't really
want to have 15 different copies of Python (or even links), and it
requires root privleges every time you want to run a Python program
with the "correct" name.

Good point about using a link. I was trying to make something that
would probably also work in Windows. As for the needing of root
privileges, that's only for those programs you need to be able to
identify with ps, and only one time for each.

Anyway, it's a response to a specific need, which I don't share, and it
was my second suggestion, not first.
 
C

Chris Angelico

Seems like an awfully obtuse way of doing things -- I don't really
want to have 15 different copies of Python (or even links), and it
requires root privleges every time you want to run a Python program
with the "correct" name.

Why do you need root? Can't you copy / link into your own home directory?

I may have misunderstood something here.

ChrisA
 
X

xliiv

Why do you need root? Can't you copy / link into your own home directory?

I may have misunderstood something here.

ChrisA

It's nice walkaround for now and for linux. But how about my question and future? :)
 
X

xliiv

Why do you need root? Can't you copy / link into your own home directory?

I may have misunderstood something here.

ChrisA

It's nice walkaround for now and for linux. But how about my question and future? :)
 
G

Grant Edwards

Why do you need root? Can't you copy / link into your own home directory?

I was thinging about daemons and system-type stuff.

One possible problem with linking from one's home directory is that
home directories are often on different filesystems than /usr/bin (or
wherever python is). Using a symlink doesn't work, the process name
still ends up as python2.6 (or whatever the real binary is called).
 
P

Prasad, Ramit

I was thinging about daemons and system-type stuff.
One possible problem with linking from one's home directory is that
homedirectories are often on different filesystems than /usr/bin (or
wherever python is). Using a symlink doesn't work, the process name
still ends up as python2.6 (or whatever the real binary is called).


Try a hardlink instead of symlink? It seems to work for me.


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
 
A

Adam Tauno Williams

Like the topic.. .
I use Python a lot, both Windows and Linux, and it's little weird to
have many python process without fast distinction which is what.

I'm not sure of my interpretation of your problem but if you want to set
the name of the running process in the process table, at least on
LINUX/UNIX, you can use the procname module available via PyPI.



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (GNU/Linux)

iEYEABECAAYFAk9t5ycACgkQLRePpNle04NyfwCdGGVuABLF15Ja8/HYhuPKvaO8
7mMAnjrMxJ7n78RdLEr1aNlxya9j1SoY
=+FT+
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top