Cannot Pass an Argument to Python with "#!/Usr/Bin/Env Python"

Cannot pass an argument to python with #!/usr/bin/env python

It is better to use environment variable to enable this. See python doc : http://docs.python.org/2/using/cmdline.html

for your case:

export PYTHONUNBUFFERED=1
script.py

#! /usr/bin/env and process names: portability at a price?

"kill-ability" on the command line can by addressed portably and reliably using the PID of the backgrounded process obtained from shell $! variable.

$ ./bintest.py & bg_pid=$! ; echo bg_pid=$bg_pid ; ps && kill $bg_pid
[1] 2993
bg_pid=2993
PID TTY TIME CMD
2410 pts/0 00:00:00 bash
2993 pts/0 00:00:00 bintest.py
2994 pts/0 00:00:00 ps
$
[1]+ Terminated ./bintest.py
$

and envtest.py

$ ./envtest.py & bg_pid=$! ; echo bg_pid=$bg_pid ; ps && kill $bg_pid
[1] 3016
bg_pid=3016
PID TTY TIME CMD
2410 pts/0 00:00:00 bash
3016 pts/0 00:00:00 python
3017 pts/0 00:00:00 ps
$
[1]+ Terminated ./envtest.py
$

As @Adam Bryzak points out, neither script cause the process title to be set on Mac OS X. So, if that feature is a firm requirement, you may need to install and use python module setproctitle with your application.

This Stackoverflow post discusses setting process title in python



Related Topics



Leave a reply



Submit