The setproctitle module allows you to change how your process and its threads appear in system monitoring tools like ps, top, or htop.
Important: Import and use the module as early as possible in your program's lifecycle. Writing environment variables later in your code may interfere with the module's initialization.
Process Title API
setproctitle(title): Sets the title for the current process.getproctitle(): Returns the current process title.
Thread Title API
setthreadtitle(title): Sets the title for the current thread.getthreadtitle(): Returns the current thread title.
import setproctitle
# Set and get process title
setproctitle.setproctitle("my_custom_process_name")
print(setproctitle.getproctitle())
# Set and get thread title
setproctitle.setthreadtitle("my_worker_thread")
print(setproctitle.getthreadtitle())