Reputation: 13109
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?
Upvotes: 0
Views: 222
Reputation: 18860
I voted for unubtu's answer. But in case this scenario is not possible for you:
You do not have to care about the variable xx. Just assign a new object to it. Re-assigning a variable does not impact the current (still running) thread. Anyway, if I'm not wrong, you did not intend to use that variable any more to get in touch with the current running thread...
Upvotes: 1
Reputation: 880587
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.
Upvotes: 4