comparison jupyter_c_kernel/kernel.py @ 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 a98647258349
comparison
equal deleted inserted replaced
38:cb587f21c8bb 39:fecdf8733f3b
1 from queue import Queue, Empty 1 from queue import Queue
2 from threading import Thread 2 from threading import Thread
3 3
4 from ipykernel.kernelbase import Kernel 4 from ipykernel.kernelbase import Kernel
5 import subprocess 5 import subprocess
6 import tempfile 6 import tempfile
43 queue.put(line) 43 queue.put(line)
44 stream.close() 44 stream.close()
45 45
46 def write_contents(self): 46 def write_contents(self):
47 """ 47 """
48 Write the available content from stdin and stderr where specifid you the instance was created 48 Write the available content from stdin and stderr where specified when the instance was created
49 :return: 49 :return:
50 """ 50 """
51 try: 51
52 stdout_contents = self._stdout_queue.get_nowait() 52 def read_all_from_queue(queue):
53 except Empty: 53 res = b''
54 pass 54 size = queue.qsize()
55 else: 55 while size != 0:
56 res += queue.get_nowait()
57 size -= 1
58 return res
59
60 stdout_contents = read_all_from_queue(self._stdout_queue)
61 if stdout_contents:
56 self._write_to_stdout(stdout_contents) 62 self._write_to_stdout(stdout_contents)
57 try: 63 stderr_contents = read_all_from_queue(self._stderr_queue)
58 stderr_contents = self._stderr_queue.get_nowait() 64 if stderr_contents:
59 except Empty:
60 pass
61 else:
62 self._write_to_stderr(stderr_contents) 65 self._write_to_stderr(stderr_contents)
63 66
64 67
65 class CKernel(Kernel): 68 class CKernel(Kernel):
66 implementation = 'jupyter_c_kernel' 69 implementation = 'jupyter_c_kernel'