示例#1
0
 def _bootstrap(self):
     from processing.finalize import _registry
     from processing.logger import info
     
     global _current_process
     try:
         self._children = set()
         self._counter = itertools.count(1)
         sys.stdin.close()
         _registry.clear()
         _current_process = self
         _runAfterForkers()
         info('child process calling self.run()')
         try:
             self.run()
             exitcode = 0
         finally:
             _exitFunction()
     except SystemExit, e:
         if not e.args:
             exitcode = 1
         elif type(e.args[0]) is int:
             exitcode = e.args[0]
         else:
             print >>sys.stderr, e.args[0]
             exitcode = 1
示例#2
0
    def _finalizeManager(process, address, authkey):
        '''
        Shutdown the manager process; will be registered as a finalizer
        '''
        if process.isAlive():
            info('sending shutdown message to manager')
            try:
                transact(address, authkey, 'shutdown')
            except (SystemExit, KeyboardInterrupt):
                raise
            except Exception:
                pass

            process.join(timeout=0.2)
            if process.isAlive():
                info('manager still alive')
                if hasattr(process, 'terminate'):
                    info('trying to `terminate()` manager process')
                    process.terminate()
                    process.join(timeout=0.1)
                    if process.isAlive():
                        info('manager still alive after terminate')

        try:
            del BaseProxy._address_to_local[address]
        except KeyError:
            pass
示例#3
0
    def _finalizeManager(process, address, authkey):
        '''
        Shutdown the manager process; will be registered as a finalizer
        '''
        if process.isAlive():
            info('sending shutdown message to manager')
            try:
                transact(address, authkey, 'shutdown')
            except (SystemExit, KeyboardInterrupt):
                raise
            except Exception:
                pass

            process.join(timeout=0.2)
            if process.isAlive():
                info('manager still alive')
                if hasattr(process, 'terminate'):
                    info('trying to `terminate()` manager process')
                    process.terminate()
                    process.join(timeout=0.1)
                    if process.isAlive():
                        info('manager still alive after terminate')

        try:
            del BaseProxy._address_to_local[address]
        except KeyError:
            pass
示例#4
0
    def _runServer(cls, registry, address, authkey, writer):
        '''
        Create a server, report its address and run it
        '''
        # create server
        server = Server(registry, address, authkey)
        currentProcess()._server = server

        # inform parent process of the server's address
        writer.send(server.address)
        writer.close()

        # run the manager
        info('manager serving at %r', server.address)
        server.serveForever()
示例#5
0
    def _runServer(cls, registry, address, authkey, writer):
        '''
        Create a server, report its address and run it
        '''
        # create server
        server = Server(registry, address, authkey)
        currentProcess()._server = server

        # inform parent process of the server's address
        writer.send(server.address)
        writer.close()

        # run the manager
        info('manager serving at %r', server.address)
        server.serveForever()
示例#6
0
    def shutdown(self, c):
        '''
        Shutdown this process
        '''
        c.send(('#RETURN', None))
        info('manager received shutdown message')

        # do some cleaning up
        _runFinalizers(0)
        for p in activeChildren():
            debug('terminating a child process of manager')
            p.terminate()
        for p in activeChildren():
            debug('terminating a child process of manager')
            p.join()
        _runFinalizers()
        info('manager exiting with exitcode 0')

        # now exit without waiting for other threads to finish
        exit(0)
示例#7
0
    def shutdown(self, c):
        '''
        Shutdown this process
        '''
        c.send(('#RETURN', None))
        info('manager received shutdown message')

        # do some cleaning up
        _runFinalizers(0)
        for p in activeChildren():
            debug('terminating a child process of manager')
            p.terminate()
        for p in activeChildren():
            debug('terminating a child process of manager')
            p.join()
        _runFinalizers()
        info('manager exiting with exitcode 0')

        # now exit without waiting for other threads to finish
        exit(0)
示例#8
0
    def _malloc(self, size):
        # returns a large enough block -- it might be much larger
        i = bisect.bisect_left(self._lengths, size)
        if i == len(self._lengths):
            length = max(self._size, size)
            self._size *= 2
            info('allocating a new mmap of length %d', length)
            arena = Arena(length)
            self._arenas.append(arena)
            return (arena, 0, length)
        else:
            length = self._lengths[i]
            seq = self._len_to_seq[length]
            block = seq.pop()
            if not seq:
                del self._len_to_seq[length], self._lengths[i]

        (arena, start, stop) = block
        del self._start_to_block[(arena, start)]
        del self._stop_to_block[(arena, stop)]
        return block
示例#9
0
文件: heap.py 项目: ConduitTeam/hue
    def _malloc(self, size):
        # returns a large enough block -- it might be much larger
        i = bisect.bisect_left(self._lengths, size)
        if i == len(self._lengths):
            length = max(self._size, size)
            self._size *= 2
            info('allocating a new mmap of length %d', length)
            arena = Arena(length)
            self._arenas.append(arena)
            return (arena, 0, length)
        else:
            length = self._lengths[i]
            seq = self._len_to_seq[length]
            block = seq.pop()
            if not seq:
                del self._len_to_seq[length], self._lengths[i]

        (arena, start, stop) = block
        del self._start_to_block[(arena, start)]
        del self._stop_to_block[(arena, stop)]
        return block
示例#10
0
def _exitFunction():
    from processing.finalize import _runFinalizers
    from processing.logger import info
    
    _current_process._exiting = True

    info('running all "atexit" finalizers with priority >= 0')
    _runFinalizers(0)

    for p in activeChildren():
        if p._daemonic:
            info('calling `terminate()` for daemon %s', p.getName())
            p._popen.terminate()

    for p in activeChildren():
        info('calling `join()` for process %s', p.getName())
        p.join()

    info('running the remaining "atexit" finalizers')
    _runFinalizers()
示例#11
0
                _exitFunction()
        except SystemExit, e:
            if not e.args:
                exitcode = 1
            elif type(e.args[0]) is int:
                exitcode = e.args[0]
            else:
                print >>sys.stderr, e.args[0]
                exitcode = 1
        except:
            exitcode = 1
            import traceback
            print >>sys.stderr, 'Process %s:' % self.getName()
            traceback.print_exc()

        info('process exiting with exitcode %d' % exitcode)
        return exitcode

#
# Create object representing the main process
#

class _MainProcess(Process):

    def __init__(self):
        self._identity = ()
        self._daemonic = False
        self._name = 'MainProcess'
        self._parent_pid = None
        self._popen = None
        self._counter = itertools.count(1)