Beispiel #1
0
 def __init__(self, obj):
     self.clsname = obj.__class__.__name__
     self.calc_id = str(getattr(obj, 'calc_id', ''))  # for monitors
     try:
         self.pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
     except TypeError as exc:  # can't pickle, show the obj in the message
         raise TypeError('%s: %s' % (exc, obj))
Beispiel #2
0
 def __toh5__(self):
     dic = {}
     nbytes = 0
     for i, obj in enumerate(self._objects):
         pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
         dic['%06d' % i] = numpy.array(pik)
         nbytes += len(pik)
     return dic, dict(nbytes=nbytes)
Beispiel #3
0
def submit_job(job_ini, user_name, hazard_job_id=None):
    """
    Create a job object from the given job.ini file in the job directory
    and run it in a new process. Returns the job ID and PID.
    """
    job_id, oq = engine.job_from_file(job_ini, user_name, hazard_job_id)
    pik = pickle.dumps(oq, protocol=0)  # human readable protocol
    code = RUNCALC % dict(job_id=job_id, hazard_job_id=hazard_job_id, pik=pik)
    tmp_py = writetmp(code, suffix='.py')
    # print(code, tmp_py)  # useful when debugging
    devnull = getattr(subprocess, 'DEVNULL', None)  # defined in Python 3
    popen = subprocess.Popen([sys.executable, tmp_py],
                             stdin=devnull, stdout=devnull, stderr=devnull)
    threading.Thread(target=popen.wait).start()
    return job_id, popen.pid
Beispiel #4
0
 def __setitem__(self, key, value):
     if (not isinstance(value, numpy.ndarray)
             or value.dtype is numpy.dtype(object)):
         val = numpy.array(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))
     else:
         val = value
     if key in self.hdf5:
         # there is a bug in the current version of HDF5 for composite
         # arrays: is impossible to save twice the same key; so we remove
         # the key first, then it is possible to save it again
         del self[key]
     try:
         self.hdf5[key] = val
     except RuntimeError as exc:
         raise RuntimeError('Could not save %s: %s in %s' %
                            (key, exc, self.hdf5path))
Beispiel #5
0
 def __setitem__(self, key, value):
     if (not isinstance(value, numpy.ndarray) or
             value.dtype is numpy.dtype(object)):
         val = numpy.array(pickle.dumps(value, pickle.HIGHEST_PROTOCOL))
     else:
         val = value
     if key in self.hdf5:
         # there is a bug in the current version of HDF5 for composite
         # arrays: is impossible to save twice the same key; so we remove
         # the key first, then it is possible to save it again
         del self[key]
     try:
         self.hdf5[key] = val
     except RuntimeError as exc:
         raise RuntimeError('Could not save %s: %s in %s' %
                            (key, exc, self.hdf5path))
Beispiel #6
0
 def __init__(self, obj):
     self.clsname = obj.__class__.__name__
     self.calc_id = str(getattr(obj, 'calc_id', ''))  # for monitors
     self.pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
Beispiel #7
0
 def __init__(self, obj):
     self.clsname = obj.__class__.__name__
     self.calc_id = str(getattr(obj, 'calc_id', ''))  # for monitors
     self.pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
Beispiel #8
0
 def __init__(self, obj):
     self.clsname = obj.__class__.__name__
     self.pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
Beispiel #9
0
 def __init__(self, obj):
     self.clsname = obj.__class__.__name__
     self.pik = pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)