Skip to content

Fix race condition which causes output to be lost sometimes #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions jupyter_c_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def _enqueue_output(stream, queue):
queue.put(line)
stream.close()

def wait_for_threads(self):
self._stdout_thread.join()
self._stderr_thread.join()

def write_contents(self):
"""
Write the available content from stdin and stderr where specified when the instance was created
Expand Down Expand Up @@ -153,18 +157,21 @@ def do_execute(self, code, silent, store_history=True,
p.write_contents()
if p.returncode != 0: # Compilation failed
self._write_to_stderr(
"[C kernel] GCC exited with code {}, the executable will not be executed".format(
p.returncode))
"[C kernel] GCC exited with code {}, the executable will not be executed".format(
p.returncode))
return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [],
'user_expressions': {}}

p = self.create_jupyter_subprocess([self.master_path, binary_file.name] + magics['args'])
while p.poll() is None:
p.write_contents()

p.wait_for_threads()
p.write_contents()

if p.returncode != 0:
self._write_to_stderr("[C kernel] Executable exited with code {}".format(p.returncode))

return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}}

def do_shutdown(self, restart):
Expand Down