I have a main thread that gets connections and immediately spawns new threads then inside the thread it receives a name that gets logged, currently my threads are named Thread-n. I would like to change the name of the thread from inside. I found this, but it sadly only works on linux, any similar program to do this on Windows?
The name for a new thread can be set via the “name” argument in the constructor to the threading.
Each thread also has an identifier. Python will assign each thread an integer identifier number. This can be retrieved via the get_ident() function. The operating system will also assign each thread a unique integer that can be retrieved by the get_native_id() function.
Yes, spawning threads from within another thread is OK. Just remember that there exists a main Python thread, that governs the others.
The threads which are always going to run in the background that provides supports to main or non-daemon threads, those background executing threads are considered as Daemon Threads. The Daemon Thread does not block the main thread from exiting and continues to run in the background.
One can do this by using:
import threading
threading.current_thread().name = "my_name"
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