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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With