當前位置: 首頁>>代碼示例>>Python>>正文


Python forking.Popen類代碼示例

本文整理匯總了Python中multiprocessing.forking.Popen的典型用法代碼示例。如果您正苦於以下問題:Python Popen類的具體用法?Python Popen怎麽用?Python Popen使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Popen類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reduce_handle

def reduce_handle(handle):
    if Popen.thread_is_spawning():
        return (None, Popen.duplicate_for_child(handle), True)
    dup_handle = duplicate(handle)
    _cache.add(dup_handle)
    sub_debug('reducing handle %d', handle)
    return (_get_listener().address, dup_handle, False)
開發者ID:Arrjaan,項目名稱:Cliff,代碼行數:7,代碼來源:reduction.py

示例2: __getstate__

    def __getstate__(self):
        assert_spawning(self)
        r = self._reader._semlock
        w = self._writer._semlock

        reader = Popen.duplicate_for_child(r.handle), r.kind, r.maxvalue
        writer = Popen.duplicate_for_child(w.handle), w.kind, w.maxvalue
        return (reader, writer)
開發者ID:sdiehl,項目名稱:numpush,代碼行數:8,代碼來源:shmem_sync.py

示例3: __reduce__

	def __reduce__(self):
		from multiprocessing.forking import Popen
		if not Popen.thread_is_spawning():
			raise TypeError(
				'Pickling an AuthenticationString object is '
				'disallowed for security reasons'
			)
		return AuthenticationString, (bytes(self),)
開發者ID:Fclem,項目名稱:isbio,代碼行數:8,代碼來源:process.py

示例4: start

 def start(self):
     '''
     Start child process
     '''
     assert self._popen is None, 'cannot start a process twice'
     assert self._parent_pid == os.getpid(), \
            'can only start a process object created by current process'
     assert not _current_process._daemonic, \
            'daemonic processes are not allowed to have children'
     _cleanup()
     if self._Popen is not None:
         Popen = self._Popen
     else:
         from multiprocessing.forking import Popen
     self._popen = Popen(self)
     _current_process._children.add(self)
開發者ID:Kappie,項目名稱:support_vector_machine,代碼行數:16,代碼來源:process.py

示例5: __getstate__

 def __getstate__(self):
     assert_spawning(self)
     sl = self._semlock
     return (Popen.duplicate_for_child(sl.handle), sl.kind, sl.maxvalue)
開發者ID:webiumsk,項目名稱:WOT-0.9.12-CT,代碼行數:4,代碼來源:synchronize.py

示例6: Process

class Process(object):
    '''
    Process objects represent activity that is run in a separate process

    The class is analagous to `threading.Thread`
    '''
    _Popen = None

    def __init__(self, group=None, target=None, name=None, args=(), kwargs={}):
        assert group is None, 'group argument must be None for now'
        count = _current_process._counter.next()
        self._identity = _current_process._identity + (count,)
        self._authkey = _current_process._authkey
        self._daemonic = _current_process._daemonic
        self._tempdir = _current_process._tempdir
        self._parent_pid = os.getpid()
        self._popen = None
        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)

    def run(self):
        '''
        Method to be run in sub-process; can be overridden in sub-class
        '''
        if self._target:
            self._target(*self._args, **self._kwargs)

    def start(self):
        '''
        Start child process
        '''
        assert self._popen is None, 'cannot start a process twice'
        assert self._parent_pid == os.getpid(), \
               'can only start a process object created by current process'
        assert not _current_process._daemonic, \
               'daemonic processes are not allowed to have children'
        _cleanup()
        if self._Popen is not None:
            Popen = self._Popen
        else:
            from multiprocessing.forking import Popen
        self._popen = Popen(self)
        _current_process._children.add(self)

    def terminate(self):
        '''
        Terminate process; sends SIGTERM signal or uses TerminateProcess()
        '''
        self._popen.terminate()

    def join(self, timeout=None):
        '''
        Wait until child process terminates
        '''
        assert self._parent_pid == os.getpid(), 'can only join a child process'
        assert self._popen is not None, 'can only join a started process'
        res = self._popen.wait(timeout)
        if res is not None:
            _current_process._children.discard(self)

    def is_alive(self):
        '''
        Return whether process is alive
        '''
        if self is _current_process:
            return True
        assert self._parent_pid == os.getpid(), 'can only test a child process'
        if self._popen is None:
            return False
        self._popen.poll()
        return self._popen.returncode is None

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        assert isinstance(name, str), 'name must be a string'
        self._name = name

    @property
    def daemon(self):
        '''
        Return whether process is a daemon
        '''
        return self._daemonic

    @daemon.setter
    def daemon(self, daemonic):
        '''
        Set whether process is a daemon
        '''
        assert self._popen is None, 'process has already started'
        self._daemonic = daemonic

    @property
#.........這裏部分代碼省略.........
開發者ID:Kappie,項目名稱:support_vector_machine,代碼行數:101,代碼來源:process.py


注:本文中的multiprocessing.forking.Popen類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。