示例#1
0
    def getKernelList(self):

        # Get info of each kernel as an ssdf struct
        infos = []
        for kernel in self._kernels:
            info = kernel._info
            info = ssdf.loads(info.tostring())
            info.name = kernel._name
            infos.append(info)

        # Done
        return infos
示例#2
0
 def getKernelList(self):
     
     # Get info of each kernel as an ssdf struct
     infos = []
     for kernel in self._kernels:
         info = kernel._info
         info = ssdf.loads(info.tostring())
         info.name = kernel._name
         infos.append(info)
     
     # Done
     return infos
示例#3
0
    def _commandRestart(self, msg):
        # Almost the same as terminate, but now we have a pending action
        self._pending_restart = True

        # Recreate the info struct
        self._info = ssdf.copy(self._originalInfo)
        # Update the info struct
        new_info = ssdf.loads(msg.split('RESTART', 1)[1])
        for key in new_info:
            self._info[key] = new_info[key]

        # Restart now, wait, or initiate termination procedure?
        if self._process is None:
            self.startKernel()
        elif self.isTerminating():
            pass  # Already terminating
        else:
            self.terminate('for restart')
示例#4
0
 def _commandRestart(self, msg):
     # Almost the same as terminate, but now we have a pending action
     self._pending_restart = True
     
     # Recreate the info struct
     self._info = ssdf.copy(self._originalInfo)
     # Update the info struct
     new_info = ssdf.loads(msg.split('RESTART',1)[1])
     for key in new_info:
         self._info[key] = new_info[key]
     
     # Restart now, wait, or initiate termination procedure?
     if self._process is None:
         self.startKernel()
     elif self.isTerminating():
         pass # Already terminating
     else:
         self.terminate('for restart')
示例#5
0
    def __init__(self, info=None):

        # ----- Fixed parameters that define a shell -----

        # scriptFile is used to define the mode. If given, we run in
        # script-mode. Otherwise we run in interactive mode.

        # The name of this shell config. Can be used to name the kernel
        self.name = 'Python'

        # The executable. This can be '/usr/bin/python3.1' or
        # 'c:/program files/python2.6/python.exe', etc.
        # The "[default]" is a placeholder text that is replaced at the last
        # moment with iep.defaultInterpreterExe()
        self.exe = '[default]'

        # The GUI toolkit to embed the event loop of.
        # Instantiate with a value that is settable
        self.gui = iep.defaultInterpreterGui() or 'none'

        # The Python path. Paths should be separated by newlines.
        # '$PYTHONPATH' is replaced by environment variable by broker
        self.pythonPath = ''

        # The path of the current project, the kernel will prepend this
        # to the sys.path. The broker could prepend to PYTHONPATH, but
        # in this way it is more explicit (kernel can tell the user that
        # the project path was prepended).
        self.projectPath = ''

        # The full filename of the script to run.
        # If given, the kernel should run in script-mode.
        # The kernel will check whether this file exists, and will
        # revert to interactive mode if it doesn't.
        self.scriptFile = ''

        # Interactive-mode only:

        # The initial directory. Only used for interactive-mode; in
        # script-mode the initial directory is the dir of the script.
        self.startDir = ''

        # The Startup script (only used for interactive-mode).
        # - Empty string means run nothing,
        # - Single line means file name
        # - multiple lines means source code.
        # - '$PYTHONSTARTUP' uses the code in that file. Broker replaces this.
        self.startupScript = ''

        # Load info from ssdf struct. Make sure they are all strings
        if info:
            # Get struct
            if isinstance(info, dict):
                s = info
            elif ssdf.isstruct(info):
                s = info
            elif isinstance(info, str):
                s = ssdf.loads(info)
            else:
                raise ValueError(
                    'Kernel info should be a string or ssdf struct, not %s' %
                    str(type(info)))
            # Inject values
            for key in s:
                val = s[key]
                if not val:
                    val = ''
                self[key] = val
示例#6
0
 def __init__(self, info=None):
     
     # ----- Fixed parameters that define a shell -----
     
     # scriptFile is used to define the mode. If given, we run in 
     # script-mode. Otherwise we run in interactive mode.
     
     # The name of this shell config. Can be used to name the kernel
     self.name = 'Python'
     
     # The executable. This can be '/usr/bin/python3.1' or 
     # 'c:/program files/python2.6/python.exe', etc.
     self.exe = ''
     
     # The GUI toolkit to embed the event loop of. 
     # Instantiate with a value that is settable
     self.gui = 'Auto'
     
     # The Python path. Paths should be separated by newlines.
     # '$PYTHONPATH' is replaced by environment variable by broker
     self.pythonPath = ''
     
     # The path of the current project, the kernel will prepend this 
     # to the sys.path. The broker could prepend to PYTHONPATH, but
     # in this way it is more explicit (kernel can tell the user that
     # the project path was prepended).
     self.projectPath = ''
     
     # The full filename of the script to run. 
     # If given, the kernel should run in script-mode.
     # The kernel will check whether this file exists, and will
     # revert to interactive mode if it doesn't.
     self.scriptFile = ''
     
     # Interactive-mode only:
     
     # The initial directory. Only used for interactive-mode; in
     # script-mode the initial directory is the dir of the script.
     self.startDir = '' 
     
     # The Startup script (only used for interactive-mode).
     # - Empty string means run nothing, 
     # - Single line means file name
     # - multiple lines means source code.
     # - '$PYTHONSTARTUP' uses the code in that file. Broker replaces this.
     self.startupScript = ''
     
     # Additional command line arguments, set by the kernel
     self.argv = ''
     
     # Additional environment variables
     self.environ = ''
     
     # Load info from ssdf struct. Make sure they are all strings
     if info:
         # Get struct
         if isinstance(info, dict):
             s = info
         elif ssdf.isstruct(info):
             s = info
         elif isinstance(info, str):
             s = ssdf.loads(info)
         else:
             raise ValueError('Kernel info should be a string or ssdf struct, not %s' % str(type(info)))
         # Inject values
         for key in s:
             val = s[key]
             if not val:
                 val = ''
             self[key] = val
示例#7
0
    def test_numpy(self, amount=10):
    
       
        
        for iter in range(amount):
            
            # Random struct            
            s = Generator.create_struct()
            self._s = s
            
            # Text with numpy on writing
            self.enable_np()            
            text = ssdf.saves(s)
            #
            self.disable_np()
            s2 = ssdf.loads(text)
            text = ssdf.saves(s2)
            #
            self.enable_np()
            s3 = ssdf.loads(text)
#             if not compare(s, s2):
#                 print('Test text failed after %i iterations.' % iter)
#                 break  
            if not compare(s, s3):
                print('Test text failed after %i iterations.' % iter)
                break  
            
            # Binary with numpy on writing
            self.enable_np()
            bb = ssdf.saveb(s)
            #            
            self.disable_np()
            s2 = ssdf.loadb(bb)
            bb = ssdf.saveb(s2)
            #
            self.enable_np()
            s3 = ssdf.loadb(bb)
#             if not compare(s, s2):
#                 print('Test bin failed after %i iterations.' % iter)
#                 break  
            if not compare(s, s3):
                print('Test bin failed after %i iterations.' % iter)
                break  
            
            print('%i tests successfull' % iter)
            time.sleep(0.001)
        
#             # Text with numpy on writing
#             self.disable_np()
#             s = Generator.create_struct()
#             text = ssdf.saves(s)
#             #
#             self.enable_np()
#             s2 = ssdf.loads(text)
#             text = ssdf.saves(s2)
#             #
#             self.disable_np()
#             s3 = ssdf.loads(text)
#             if not compare(s, s3):
#                 print('Test text failed after %i iterations.' % iter)
#                 break  
#             
#             # Binary with numpy on writing
#             self.disable_np()
#             s = Generator.create_struct()
#             bb = ssdf.saveb(s)
#             #            
#             self.enable_np()
#             s2 = ssdf.loadb(bb)
#             bb = ssdf.saveb(s2)
#             #
#             self.disable_np()
#             s3 = ssdf.loadb(bb)
#             if not compare(s, s3):
#                 print('Test bin failed after %i iterations.' % iter)
#                 break  
        
        # Finish
        self.enable_np()
示例#8
0
 def run(self, amount=100000):
     self._stop = False
     t0 = time.time()
     maxtests = amount
     
     while len(self._tests) < maxtests and not self._stop:
         
         # Create struct
         s = Generator.create_struct()
         n = ssdf.count(s)
         self._s = s
         
         # times
         times = []
         sizes = []
         
         # Test text
         t1 = time.time()
         text = ssdf.saves(s)
         times.append(time.time()-t1)
         #
         t1 = time.time()
         s2 = ssdf.loads(text)
         times.append(time.time()-t1)
         #
         if not compare(s, s2):
             print('Test text failed after %i iterations.' % len(self._tests))
             break
         
         # Test binary
         t1 = time.time()
         bb = ssdf.saveb(s)
         times.append(time.time()-t1)
         #
         t1 = time.time()
         s2 = ssdf.loadb(bb)
         times.append(time.time()-t1)
         #
         if not compare(s, s2):
             print('Test bin failed after %i iterations.' % len(self._tests))
             break
         
         # Test text file
         fname = homedir+'projects/ssdftest.ssdf'
         t1 = time.time()
         ssdf.save(fname, s)
         times.append(time.time()-t1)
         #
         t1 = time.time()
         s2 = ssdf.load(fname)
         times.append(time.time()-t1)
         sizes.append(os.stat(fname).st_size)
         #
         if not compare(s, s2):
             print('Test text-file failed after %i iterations.' % len(self._tests))
             break
             
         # Test binary file
         fname = homedir+'projects/ssdftest.bsdf'
         t1 = time.time()
         ssdf.save(fname, s)
         times.append(time.time()-t1)
         #
         t1 = time.time()
         s2 = ssdf.load(fname)
         times.append(time.time()-t1)
         sizes.append(os.stat(fname).st_size)
         #
         if not compare(s, s2):
             print('Test bin-file failed after %i iterations.' % len(self._tests))
             break
         
         # Success
         self._tests.append( (n, times, sizes) )
         print('%i tests successfull' % len(self._tests))
         time.sleep(0.001)