Note that there are some explanatory texts on larger screens.

plurals
  1. POpython multiprocessing.Queue.get() prints None at unwanted moments
    text
    copied!<p>I have a piece of python code that listens for messages sent by a child process. The message can either be a normal string that is printed directly to a console window, or a tuple with an exception object and traceback ouput that is to be processed somewhere else in the program. The multiprocessing.Queue implementation is used for inter-process communication. The queue object is referenced by self.channel. </p> <pre><code>while self.exp_process.is_alive() or not self.channel.empty(): # Make sure Qt interface stays responsive, gets redrawn, etc. QtGui.QApplication.processEvents() # Check if messages are pending to be processed # Sleep otherwise if not self.channel.empty(): # Encapsulated by print statements for debugging of None print print "Retrieving message" msg = self.channel.get(False) print "Message received" # Directly print received strings if type(msg) in [str, unicode]: sys.stdout.write(msg) # Errors arrive as a tuple with (Error object, traceback) elif type(msg) == tuple and isinstance(msg[0], Exception): return msg else: sys.stderr.write(u"Illegal message type received from child process") else: time.sleep(0.1) </code></pre> <p>When a msg is a tuple (containing error info from the child process), the</p> <pre><code>msg = self.channel.get(False) </code></pre> <p>appears to print None, as the output in the console is</p> <pre><code>Retrieving message None Message received </code></pre> <p>After this, the tuple contained by msg is processed as it should, indicating that the correct info was received. It seems that None is printed somewhere inside the Queue.get() function, when receiving a tuple. Is there anyway to suppress its output, or fix this? </p>
 

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