def __init__(self, **kwds): for key in kwds.keys(): print( "WorksheetProcess_ReferenceImplementation: does not support '%s' option. Ignored." % key) self._output_status = OutputStatus('', [], True, None) self._state = {}
def output_status(self): """ Return OutputStatus object, which includes output from the subprocess from the last executed command up until now, information about files that were created, and whether computing is now done. OUTPUT: - ``OutputStatus`` object. """ OS = self._output_status self._output_status = OutputStatus('', [], True) return OS
def execute(self, string, data=None): """ Start executing the given string in this subprocess. INPUT: ``string`` -- a string containing code to be executed. - ``data`` -- a string or None; if given, must specify an absolute path on the server host filesystem. This may be ignored by some worksheet process implementations. """ out, files, tempdir = execute_code(string, self._state, data) self._output_status = OutputStatus(out, files, True, tempdir)
def output_status(self): """ Return OutputStatus object, which includes output from the subprocess from the last executed command up until now, information about files that were created, and whether computing is now done. OUTPUT: - ``OutputStatus`` object. """ self._read() if self._expect is None: self._is_computing = False else: self._so_far += self._expect.before import re v = re.findall('START%s.*%s' % (self._number, self._prompt), self._so_far, re.DOTALL) if len(v) > 0: self._is_computing = False s = v[0][len('START%s' % self._number):-len(self._prompt)] else: v = re.findall('START%s.*' % self._number, self._so_far, re.DOTALL) if len(v) > 0: s = v[0][len('START%s' % self._number):] else: s = '' if s.endswith(self._prompt): s = s[:-len(self._prompt)] files = [] if os.path.exists(self._tempdir): files = [ os.path.join(self._tempdir, x) for x in os.listdir(self._tempdir) if x != self._data ] files = [x for x in files if x != self._filename] return OutputStatus(s, files, not self._is_computing)
def __init__(self, process_limits=None, timeout=0.05, python='python'): """ Initialize this worksheet process. """ self._output_status = OutputStatus('', [], True) self._expect = None self._is_started = False self._is_computing = False self._timeout = timeout self._prompt = "__SAGE__" self._filename = '' self._all_tempdirs = [] self._process_limits = process_limits self._max_walltime = None self._start_walltime = None self._data_dir = None self._python = python if process_limits: u = '' if process_limits.max_vmem is not None: u += ' -v %s' % (int(process_limits.max_vmem) * 1000) if process_limits.max_cputime is not None: u += ' -t %s' % (int(process_limits.max_cputime)) if process_limits.max_processes is not None: u += ' -u %s' % (int(process_limits.max_processes)) # prepend ulimit options if u == '': self._ulimit = u else: self._ulimit = 'ulimit %s' % u else: self._ulimit = '' if process_limits and process_limits.max_walltime: self._max_walltime = process_limits.max_walltime