Пример #1
0
def supervise(pid, job_id, timeout=1):
    """
    Supervise a job process, entering a loop that ends only when the job
    terminates.

    :param pid: the process id
    :type pid: int
    :param job_id: the job id
    :type job_id: int
    :param timeout: timeout value in seconds
    :type timeout: float
    """
    # Set the name of this process (as reported by /bin/ps)
    setproctitle('openquake supervisor for job_id=%s job_pid=%s'
                 % (job_id, pid))
    ignore_sigint()

    logging.root.addHandler(SupervisorLogHandler(job_id))
    logs.set_logger_level(logging.root, flags.FLAGS.debug)

    supervisor = SupervisorLogMessageConsumer(job_id, pid, timeout)
    supervisor.run()
Пример #2
0
            _launch_job(job_ctxt, sections)
        except Exception, ex:
            logs.LOG.critical("Calculation failed with exception: '%s'"
                              % str(ex))
            job.status = 'failed'
            job.save()
            raise
        else:
            job.status = 'succeeded'
            job.save()
        return

    supervisor_pid = os.fork()
    if not supervisor_pid:
        # supervisor process
        logs.set_logger_level(logs.logging.root, log_level)
        supervisor_pid = os.getpid()
        job.supervisor_pid = supervisor_pid
        job.job_pid = job_pid
        job.save()
        supervisor.supervise(job_pid, job.id)
        return

    # parent process

    # ignore Ctrl-C as well as supervisor process does. thus only
    # job executor terminates on SIGINT
    supervisor.ignore_sigint()
    # wait till both child processes are done
    os.waitpid(job_pid, 0)
    os.waitpid(supervisor_pid, 0)
Пример #3
0
from itertools import izip
from numpy import zeros
from numpy import empty
from numpy import allclose
from numpy import sin, cos, arctan2, sqrt, radians

from shapely import geometry
from scipy.interpolate import interp1d

from openquake import java
from openquake.utils import round_float
from openquake import logs

LOGGER = logs.LOG

logs.set_logger_level(LOGGER, logs.LEVELS.get('debug'))

LineString = geometry.LineString  # pylint: disable=C0103
Point = geometry.Point            # pylint: disable=C0103


class Region(object):
    """A container of polygons, used for bounds checking"""

    def __init__(self, polygon):
        self._grid = None
        # TODO(JMC): Make this a multipolygon instead?
        self.polygon = polygon
        self.cell_size = 0.1

    @classmethod
Пример #4
0
from itertools import izip
from numpy import zeros
from numpy import empty
from numpy import allclose
from numpy import sin, cos, arctan2, sqrt, radians

from shapely import geometry
from scipy.interpolate import interp1d

from openquake import java
from openquake.utils import round_float
from openquake import logs

LOGGER = logs.LOG

logs.set_logger_level(LOGGER, logs.LEVELS.get("debug"))

LineString = geometry.LineString  # pylint: disable=C0103
Point = geometry.Point  # pylint: disable=C0103


class Region(object):
    """A container of polygons, used for bounds checking"""

    def __init__(self, polygon):
        self._grid = None
        # TODO(JMC): Make this a multipolygon instead?
        self.polygon = polygon
        self.cell_size = 0.1

    @classmethod
Пример #5
0
from numpy import empty
from numpy import allclose
from numpy import sin, cos, arctan2, sqrt, radians

from shapely import geometry
from scipy.interpolate import interp1d

from nhlib import geo as nhlib_geo

from openquake import java
from openquake.utils import round_float
from openquake import logs

LOGGER = logs.LOG

logs.set_logger_level(LOGGER, logs.LEVELS.get('debug'))


class Region(object):
    """A container of polygons, used for bounds checking."""

    def __init__(self, polygon):
        self._grid = None
        self.cell_size = 0.1
        self.polygon = polygon

    @classmethod
    def from_coordinates(cls, coordinates):
        """
        Build a region from a list of polygon coordinates.
Пример #6
0
            _launch_job(job_ctxt, sections)
        except Exception, ex:
            logs.LOG.critical("Calculation failed with exception: '%s'" %
                              str(ex))
            job.status = 'failed'
            job.save()
            raise
        else:
            job.status = 'succeeded'
            job.save()
        return

    supervisor_pid = os.fork()
    if not supervisor_pid:
        # supervisor process
        logs.set_logger_level(logs.logging.root, log_level)
        supervisor_pid = os.getpid()
        job.supervisor_pid = supervisor_pid
        job.job_pid = job_pid
        job.save()
        supervisor.supervise(job_pid, job.id, log_file=log_file)
        return

    # parent process

    # ignore Ctrl-C as well as supervisor process does. thus only
    # job executor terminates on SIGINT
    supervisor.ignore_sigint()
    # wait till both child processes are done
    os.waitpid(job_pid, 0)
    os.waitpid(supervisor_pid, 0)