Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since there was never a real answer to this question I will summarize:</p> <ol> <li>One Main thread which handles the sending, and spawns a receiving thread</li> <li>Block forever, exceptions are costly, so there is no need to let it time out.</li> </ol> <p>In order to stop the thread I basically set the stop flag then terminate the underlying connection in a "terminate" message of the parent. In return which causes an exception in the child. </p> <p>In the exception handling block I then check the ConnectionException, if the"stop" flag has been set, I gracefully stop the receiving thread, if it was an ungraceful exit, I will then notify the parent thread.</p> <p>Hope this helps, this was a super annoying problem, but I am glad it is over.</p> <pre><code>class Manager: def __init__(self): self.receiver = MessageReceiver(shutdown_hook = self.shutdown_hook) self.receiver.start() #do other stuff sending/etc... def terminate(self): self.receiver.stop() self.receiver.close() def shutdown_hook(self, t_id, child): print '%s - Unexpected thread shutdown, handle this.. restart thread?' % str(t_id)) class MessageReceiver(Thread): def __init__(self,shutdown_hook = None): Thread.__init__(self) self.receiver = Receiver() self.shutdown_hook = shutdown_hook def run(self): #stop is a flag that i use to stop the thread... while(not stopped ): try: message = self.receiver.pull() print "Message" + message except ConnectionException as e: if stopped: #we are in the process of stopping pass else: self.shutdown_hook(self.iden, e) break finally: receiver.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload