Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set title/name of a thread in Python? [duplicate]

I would like to set the title of a thread (the title seen in ps or top)in Python in order to make it visible to process tracer programs. All the threads of a process are always called python or called file name when /usr/bin/python is used and the script is called via ./script.

Now, I want to change each thread's name. I have a simple script with 4 threads (incl main thread). I use threading to start the threads.

Is there a way that I could achieve this without having to install third-party stuff? Any guidance is appreciated.

like image 903
mozcelikors Avatar asked Jun 27 '17 15:06

mozcelikors


1 Answers

Try this:

def your_function(arg1, arg2, argn):
    * do stuff *


new_thread = threading.Thread(target=your_function, args=(arg1, arg2, argn))
new_thread.name = 'your name'
new.thread.start()

Where new_thread.name is your answer.

like image 153
Nicolas Iceberg Avatar answered Sep 28 '22 02:09

Nicolas Iceberg