Example #1
0
File: os.py Project: 00arthur00/PWM
    def fork_gevent():
        """
        Forks the process using :func:`os.fork` and prepares the
        child process to continue using gevent before returning.

        .. note::

            The PID returned by this function may not be waitable with
            either the original :func:`os.waitpid` or this module's
            :func:`waitpid` and it may not generate SIGCHLD signals if
            libev child watchers are or ever have been in use. For
            example, the :mod:`gevent.subprocess` module uses libev
            child watchers (which parts of gevent use libev child
            watchers is subject to change at any time). Most
            applications should use :func:`fork_and_watch`, which is
            monkey-patched as the default replacement for
            :func:`os.fork` and implements the ``fork`` function of
            this module by default, unless the environment variable
            ``GEVENT_NOWAITPID`` is defined before this module is
            imported.

        .. versionadded:: 1.1b2
        """
        result = _raw_fork()
        if not result:
            reinit()
        return result
Example #2
0
    def init_process(self):
        self.patch()

        # prepare the gevent hub to run in a new (forked) process.
        # This should be called immediately after :func:`os.fork`
        # in the child process.
        hub.reinit()
        super().init_process()
Example #3
0
        def init_process(self):
            # monkey patch here
            self.patch()

            # reinit the hub
            from gevent import hub
            hub.reinit()

            # then initialize the process
            super(ThriftGeventWorker, self).init_process()
Example #4
0
    def test_hub_reinit(self):
        import os
        from gevent.hub import reinit
        self.pmt.pid = -1
        old_tid = self.pmt.monitor_thread_ident

        reinit(self.hub)

        self.assertEqual(os.getpid(), self.pmt.pid)
        self.assertEqual(old_tid + 1, self.pmt.monitor_thread_ident)
    def test_hub_reinit(self):
        import os
        from gevent.hub import reinit
        self.pmt.pid = -1
        old_tid = self.pmt.monitor_thread_ident

        reinit(self.hub)

        self.assertEqual(os.getpid(), self.pmt.pid)
        self.assertEqual(old_tid + 1, self.pmt.monitor_thread_ident)
Example #6
0
    def _init_process(self):
        # monkey patch here
        self._patch()

        # reinit the hub
        from gevent import hub
        hub.reinit()

        self._write_queue = Queue()
        self._read_queue = Queue()

        # then initialize the process
        super(GeventWorker, self)._init_process()
Example #7
0
File: os.py Project: 00arthur00/PWM
        def forkpty_gevent():
            """
            Forks the process using :func:`os.forkpty` and prepares the
            child process to continue using gevent before returning.

            Returns a tuple (pid, master_fd). The `master_fd` is *not* put into
            non-blocking mode.

            Availability: Some Unix systems.

            .. seealso:: This function has the same limitations as :func:`fork_gevent`.

            .. versionadded:: 1.1b5
            """
            pid, master_fd = _raw_forkpty()
            if not pid:
                reinit()
            return pid, master_fd
Example #8
0
    def init_process(self):

        # HACK:
        # https://github.com/benoitc/gunicorn/issues/336
        # https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/ggevent.py#L167
        # if gevent.version_info[0] == 0:
        from gevent import version_info
        if version_info[0] == 0:
            # reinit the hub
            import gevent.core
            gevent.core.reinit()

            # gevent 0.13 and older doesn't reinitialize dns for us after forking
            # here's the workaround
            gevent.core.dns_shutdown(fail_requests=1)
            gevent.core.dns_init()
        else:
            # reinit the hub
            from gevent import hub
            hub.reinit()

        util.set_owner_process(self.cfg.uid, self.cfg.gid)

        # Reseed the random number generator
        util.seed()

        # For waking ourselves up
        self.PIPE = os.pipe()
        map(util.set_non_blocking, self.PIPE)
        map(util.close_on_exec, self.PIPE)

        # Prevent fd inherientence
        util.close_on_exec(self.socket)
        util.close_on_exec(self.tmp.fileno())

        map(lambda s: signal.signal(s, signal.SIG_DFL), self.SIGNALS)
        self.booted = True
Example #9
0
 def fork():
     result = _fork()
     if not result:
         reinit()
     return result
Example #10
0
 def fork():
     result = _fork()
     if not result:
         reinit()
     return result
Example #11
0
 def init_process(self):
     self.patch()
     hub.reinit()
     super().init_process()
Example #12
0
 def init_process(self):
     self.patch()
     hub.reinit()
     super().init_process()
Example #13
0
 def init_process(self):
     self.patch()
     hub.reinit()
     super(GeventWorker, self).init_process()