Set the process name of the Python program

From time to time, you may want to change the process name of the program you are running. In Python, it seems better to use a package called setproctitle.

Installation

Debian, Ubuntu and Mint can be installed in one shot with the following command.

# aptitude install setproctitle

Or it is uploaded to pypi, so install it with pip. Since it is partly written in C and you need to refer to the Python header file to compile, install python-dev for Debian or Ubuntu.

# aptitude install python-dev python-pip
# pip install setproctitle

Run

You can set the process name with setproctitle and get the current process name with getproctitle as shown below. Let's check if the process name is actually changed by doing something like "pgrep hoge".

>>> from setproctitle import setproctitle, getproctitle
>>> getproctitle()
'python'
>>> setproctitle("hoge")
>>> getproctitle()
'hoge'
>>>

Recommended Posts

Set the process name of the Python program
the zen of Python
Send Gmail at the end of the process [Python]
[Python] A program that counts the number of valleys
Towards the retirement of Python2
The process of installing Atom and getting Python running
About the ease of Python
Python program that looks for the same file name
About the features of Python
[Python] A program that compares the positions of kangaroos.
The Power of Pandas: Python
Measure the execution result of the program in C ++, Java, Python.
Debug by attaching to the Python process of the SSH destination
The process of making Python code object-oriented and improving it
The story of Python and the story of NaN
[Python] The stumbling block of import
First Python 3 ~ The beginning of repetition ~
Existence from the viewpoint of Python
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
[Python] Understanding the potential_field_planning of Python Robotics
Review of the basics of Python (FizzBuzz)
Get the host name in Python
About the basics list of Python basics
The story of writing a program
Learn the basics of Python ① Beginners
[Python] Let's reduce the number of elements in the result in set operations
[Python of Hikari-] Chapter 07-02 Exception handling (continuous execution of the program by exception handling)
Get and set the value of the dropdown menu using Python and Selenium
[Python] A program that rotates the contents of the list to the left
Create a compatibility judgment program with the random module of python.
Change the length of Python csv strings
[Python] Set the graph range with matplotlib
Check the behavior of destructor in Python
[pyqtgraph] Set the size ratio of the graph
[Python3] Understand the basics of Beautiful Soup
Pass the path of the imported python module
The story of making Python an exe
Implement part of the process in C ++
Learning notes from the beginning of Python 1
Check the existence of the file with python
About the virtual environment of python version 3.7
[Python] Get the variable name with str
[Python] Understand the content of error messages
Where is the python instantiation process written?
I didn't know the basics of Python
Associate the table set in python models.py
The result of installing python in Anaconda
[Python] Try pydash of the Python version of lodash
[python] Checking the memory consumption of variables
Check the path of the Python imported module
The story of manipulating python global variables
[python] [meta] Is the type of python a type?
The basics of running NoxPlayer in Python
Pandas of the beginner, by the beginner, for the beginner [Python]
The Python project template I think of.
Effective Python was, as the name implies, Effective
Python Basic Course (at the end of 15)
[Python] Get the character code of the file
The story of blackjack A processing (python)
Intuitively learn the reshape of Python np