Example #1
0
    def __repr__(self):
        exitcode = None
        if self is _current_process:
            status = 'started'
        elif self._closed:
            status = 'closed'
        # Begin Truffle change
        # elif self._parent_pid != os.getpid():
        elif self._parent_pid != _gettid():
            # End Truffle change
            status = 'unknown'
        elif self._popen is None:
            status = 'initial'
        else:
            exitcode = self._popen.poll()
            if exitcode is not None:
                status = 'stopped'
            else:
                status = 'started'

        info = [type(self).__name__, 'name=%r' % self._name]
        if self._popen is not None:
            info.append('pid=%s' % self._popen.pid)
        info.append('parent=%s' % self._parent_pid)
        info.append(status)
        if exitcode is not None:
            exitcode = _exitcode_to_name.get(exitcode, exitcode)
            info.append('exitcode=%s' % exitcode)
        if self.daemon:
            info.append('daemon')
        return '<%s>' % ' '.join(info)
Example #2
0
 def __init__(self,
              group=None,
              target=None,
              name=None,
              args=(),
              kwargs={},
              *,
              daemon=None):
     assert group is None, 'group argument must be None for now'
     count = next(_process_counter)
     self._identity = _current_process._identity + (count, )
     self._config = _current_process._config.copy()
     # Begin Truffle change
     # self._parent_pid = os.getpid()
     self._parent_pid = _gettid()
     # End Truffle change
     self._parent_name = _current_process.name
     self._popen = None
     self._closed = False
     self._target = target
     self._args = tuple(args)
     self._kwargs = dict(kwargs)
     self._name = name or type(self).__name__ + '-' + \
                  ':'.join(str(i) for i in self._identity)
     if daemon is not None:
         self.daemon = daemon
     _dangling.add(self)
Example #3
0
 def ident(self):
     '''
     Return identifier (PID) of process or `None` if it has yet to start
     '''
     self._check_closed()
     if self is _current_process:
         # Begin Truffle change
         # return os.getpid()
         return _gettid()
         # End Truffle change
     else:
         return self._popen and self._popen.pid
Example #4
0
 def join(self, timeout=None):
     '''
     Wait until child process terminates
     '''
     self._check_closed()
     # Begin Truffle change
     # assert self._parent_pid == os.getpid(), 'can only join a child process'
     assert self._parent_pid == _gettid(), 'can only join a child process'
     # End Truffle change
     assert self._popen is not None, 'can only join a started process'
     res = self._popen.wait(timeout)
     if res is not None:
         _children.discard(self)
Example #5
0
    def is_alive(self):
        '''
        Return whether process is alive
        '''
        self._check_closed()
        if self is _current_process:
            return True
        # Begin Truffle change
        # assert self._parent_pid == os.getpid(), 'can only test a child process'
        assert self._parent_pid == _gettid(), 'can only test a child process'
        # End Truffle change

        if self._popen is None:
            return False

        returncode = self._popen.poll()
        if returncode is None:
            return True
        else:
            _children.discard(self)
            return False
Example #6
0
 def start(self):
     '''
     Start child process
     '''
     self._check_closed()
     assert self._popen is None, 'cannot start a process twice'
     # Begin Truffle change
     # assert self._parent_pid == os.getpid(), \
     # 'can only start a process object created by current process'
     assert self._parent_pid == _gettid(), \
            'can only start a process object created by current process'
     # End Truffle change
     assert not _current_process._config.get('daemon'), \
            'daemonic processes are not allowed to have children'
     _cleanup()
     self._popen = self._Popen(self)
     self._sentinel = self._popen.sentinel
     # Avoid a refcycle if the target function holds an indirect
     # reference to the process object (see bpo-30775)
     del self._target, self._args, self._kwargs
     _children.add(self)
Example #7
0
    def __init__(self, obj, callback, args=(), kwargs=None, exitpriority=None):
        if (exitpriority is not None) and not isinstance(exitpriority, int):
            raise TypeError(
                "Exitpriority ({0!r}) must be None or int, not {1!s}".format(
                    exitpriority, type(exitpriority)))

        if obj is not None:
            self._weakref = weakref.ref(obj, self)
        elif exitpriority is None:
            raise ValueError("Without object, exitpriority cannot be None")

        self._callback = callback
        self._args = args
        self._kwargs = kwargs or {}
        self._key = (exitpriority, next(_finalizer_counter))
        # Begin Truffle change
        #        self._pid = os.getpid()
        self._pid = _gettid()
        # End Truffle change

        _finalizer_registry[self._key] = self