I have a python thread, assigned to a variable name xx, which, when it completes its’ run function triggers a callback.
The callback eventually tries to create a new instance of that thread with variable name xx, effectively restarting the thread.
Of course, checking xx.isAlive() returns True (since it initiated the callback and has not reached the bottom of its stack). Since xx is still alive, replacing xx seems like a bad idea.
Is one way to deal with this to wait a moment (e.g. gobject.idle_add) before recreating xx so that the run function can complete? Or should I not worry about assigning a new thread instance to xx since the original thread is as good as done anyways by the time it is triggers that callback to recreate itself?
Without understanding the details of your situation, my knee-jerk reaction is to say, Don’t recreate the thread — reuse the established one. It takes less time to reuse the established thread than it would to shut it down and start a new one.