Mercurial > hg > Members > aka > jupyter_CbC_kernel
changeset 39:fecdf8733f3b remote/issue-4
Make sure to empty the queue so no message should be left over in it
author | Brendan Rius <brendan@omixy.com> |
---|---|
date | Mon, 16 May 2016 09:43:47 +0100 |
parents | cb587f21c8bb |
children | 758e2e0670c5 |
files | jupyter_c_kernel/kernel.py |
diffstat | 1 files changed, 15 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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)