# HG changeset patch # User Brendan Rius # Date 1463388227 -3600 # Node ID fecdf8733f3b409e4cd57db1b21d6fa82ed6f98a # Parent cb587f21c8bb6de6a97c397b4a48050e2571bd8a Make sure to empty the queue so no message should be left over in it diff -r cb587f21c8bb -r fecdf8733f3b jupyter_c_kernel/kernel.py --- a/jupyter_c_kernel/kernel.py Sat Apr 30 23:05:43 2016 +0100 +++ b/jupyter_c_kernel/kernel.py Mon May 16 09:43:47 2016 +0100 @@ -1,4 +1,4 @@ -from queue import Queue, Empty +from queue import Queue from threading import Thread from ipykernel.kernelbase import Kernel @@ -45,20 +45,23 @@ def write_contents(self): """ - Write the available content from stdin and stderr where specifid you the instance was created + Write the available content from stdin and stderr where specified when the instance was created :return: """ - try: - stdout_contents = self._stdout_queue.get_nowait() - except Empty: - pass - else: + + def read_all_from_queue(queue): + res = b'' + size = queue.qsize() + while size != 0: + res += queue.get_nowait() + size -= 1 + return res + + stdout_contents = read_all_from_queue(self._stdout_queue) + if stdout_contents: self._write_to_stdout(stdout_contents) - try: - stderr_contents = self._stderr_queue.get_nowait() - except Empty: - pass - else: + stderr_contents = read_all_from_queue(self._stderr_queue) + if stderr_contents: self._write_to_stderr(stderr_contents)