Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Stomp.py return message from listener
  2. rcvd_msg = None
  3. lock = thread.Condition()
  4.  
  5. # executed in the main thread
  6. with lock:
  7.     while rcvd_msg == None:
  8.         lock.wait()
  9.     # read rcvd_msg
  10.     rcvd_msg = None
  11.     lock.notifyAll()
  12.  
  13. class Listener(ConnectionListener):      
  14.  
  15.     def on_message(self, headers, message):
  16.         # executed in the receiver thread
  17.         global rcvd_msg, lock
  18.         with lock:
  19.             while rcvd_msg != None:
  20.                 lock.wait()
  21.             rcvd_msg = message
  22.             lock.notifyAll()