diff jupyter_c_kernel/kernel.py @ 36:8acbab5a9f21

Remove stream buffering on stdout & stderr
author Louis 'Kureuil' Person <louis.person@epitech.eu>
date Sat, 30 Apr 2016 23:48:19 +0200
parents e05900c7967e
children aac47bc07111
line wrap: on
line diff
--- a/jupyter_c_kernel/kernel.py	Sat Apr 30 22:47:49 2016 +0100
+++ b/jupyter_c_kernel/kernel.py	Sat Apr 30 23:48:19 2016 +0200
@@ -5,7 +5,7 @@
 import subprocess
 import tempfile
 import os
-
+import os.path as path
 
 class JupyterSubprocess(subprocess.Popen):
     def __init__(self, cmd, write_to_stdout, write_to_stderr):
@@ -59,11 +59,17 @@
     def __init__(self, *args, **kwargs):
         super(CKernel, self).__init__(*args, **kwargs)
         self.files = []
+        mastertemp = tempfile.mkstemp(suffix='.out')
+        os.close(mastertemp[0])
+        self.master_path = mastertemp[1]
+        filepath = path.join(path.dirname(path.realpath(__file__)), '..', 'resources', 'master.c')
+        subprocess.call(['gcc', filepath, '-std=c11', '-fPIC', '-shared', '-rdynamic', '-o', self.master_path])
 
     def cleanup_files(self):
         """Remove all the temporary files created by the kernel"""
         for file in self.files:
             os.remove(file)
+        os.remove(self.master_path)
 
     def new_temp_file(self, **kwargs):
         """Create a new temp file to be deleted when the kernel shuts down"""
@@ -86,7 +92,7 @@
                                  lambda contents: self._write_to_stderr(contents.decode()))
 
     def compile_with_gcc(self, source_filename, binary_filename):
-        args = ['gcc', source_filename, '-std=c11', '-o', binary_filename]
+        args = ['gcc', source_filename, '-std=c11', '-fPIC', '-shared', '-rdynamic', '-o', binary_filename]
         return self.create_jupyter_subprocess(args)
 
     def do_execute(self, code, silent, store_history=True,
@@ -106,7 +112,7 @@
                     return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [],
                             'user_expressions': {}}
 
-        p = self.create_jupyter_subprocess([binary_file.name])
+        p = self.create_jupyter_subprocess([self.master_path, binary_file.name])
         while p.poll() is None:
             p.write_contents()
         p.write_contents()