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


Python process.current_process方法代碼示例

本文整理匯總了Python中multiprocessing.process.current_process方法的典型用法代碼示例。如果您正苦於以下問題:Python process.current_process方法的具體用法?Python process.current_process怎麽用?Python process.current_process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在multiprocessing.process的用法示例。


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

示例1: __repr__

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def __repr__(self):
        try:
            if self._semlock._is_mine():
                name = current_process().name
                if threading.current_thread().name != 'MainThread':
                    name += '|' + threading.current_thread().name
            elif self._semlock._get_value() == 1:
                name = 'None'
            elif self._semlock._count() > 0:
                name = 'SomeOtherThread'
            else:
                name = 'SomeOtherProcess'
        except Exception:
            name = 'unknown'
        return '<Lock(owner=%s)>' % name

#
# Recursive lock
# 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:synchronize.py

示例2: get_command_line

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def get_command_line():
        '''
        Returns prefix of command line used for spawning a child process
        '''
        if getattr(process.current_process(), '_inheriting', False):
            raise RuntimeError('''
            Attempt to start a new process before the current process
            has finished its bootstrapping phase.

            This probably means that you are on Windows and you have
            forgotten to use the proper idiom in the main module:

                if __name__ == '__main__':
                    freeze_support()
                    ...

            The "freeze_support()" line can be omitted if the program
            is not going to be frozen to produce a Windows executable.''')

        if getattr(sys, 'frozen', False):
            return [sys.executable, '--multiprocessing-fork']
        else:
            prog = 'from multiprocessing.forking import main; main()'
            opts = util._args_from_interpreter_flags()
            return [_python_exe] + opts + ['-c', prog, '--multiprocessing-fork'] 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:forking.py

示例3: __repr__

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def __repr__(self):
        try:
            if self._semlock._is_mine():
                name = process.current_process().name
                if threading.current_thread().name != 'MainThread':
                    name += '|' + threading.current_thread().name
            elif self._semlock._get_value() == 1:
                name = 'None'
            elif self._semlock._count() > 0:
                name = 'SomeOtherThread'
            else:
                name = 'SomeOtherProcess'
        except Exception:
            name = 'unknown'
        return '<%s(owner=%s)>' % (self.__class__.__name__, name)


#
# Recursive lock
# 
開發者ID:joblib,項目名稱:loky,代碼行數:22,代碼來源:synchronize.py

示例4: main

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def main():
    '''
    Run code specified by data received over pipe
    '''
    assert is_forking(sys.argv)

    handle = int(sys.argv[-1])
    fd = msvcrt.open_osfhandle(handle, os.O_RDONLY)
    from_parent = os.fdopen(fd, 'rb')

    process.current_process()._inheriting = True
    preparation_data = load(from_parent)
    spawn.prepare(preparation_data)
    self = load(from_parent)
    process.current_process()._inheriting = False

    from_parent.close()

    exitcode = self._bootstrap()
    exit(exitcode) 
開發者ID:joblib,項目名稱:loky,代碼行數:22,代碼來源:popen_loky_win32.py

示例5: _check_not_importing_main

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def _check_not_importing_main():
    if getattr(process.current_process(), '_inheriting', False):
        raise RuntimeError('''
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.''') 
開發者ID:joblib,項目名稱:loky,代碼行數:18,代碼來源:spawn.py

示例6: get_temp_dir

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def get_temp_dir():
    # get name of a temp directory which will be automatically cleaned up
    if current_process()._tempdir is None:
        import shutil, tempfile
        tempdir = tempfile.mkdtemp(prefix='pymp-')
        info('created temp directory %s', tempdir)
        Finalize(None, shutil.rmtree, args=[tempdir], exitpriority=-100)
        current_process()._tempdir = tempdir
    return current_process()._tempdir

#
# Support for reinitialization of objects when bootstrapping a child process
# 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:15,代碼來源:util.py

示例7: _exit_function

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def _exit_function(info=info, debug=debug, _run_finalizers=_run_finalizers,
                   active_children=active_children,
                   current_process=current_process):
    # We hold on to references to functions in the arglist due to the
    # situation described below, where this function is called after this
    # module's globals are destroyed.

    global _exiting

    if not _exiting:
        _exiting = True

        info('process shutting down')
        debug('running all "atexit" finalizers with priority >= 0')
        _run_finalizers(0)

        if current_process() is not None:
            # We check if the current process is None here because if
            # it's None, any call to ``active_children()`` will raise
            # an AttributeError (active_children winds up trying to
            # get attributes from util._current_process).  One
            # situation where this can happen is if someone has
            # manipulated sys.modules, causing this module to be
            # garbage collected.  The destructor for the module type
            # then replaces all values in the module dict with None.
            # For instance, after setuptools runs a test it replaces
            # sys.modules with a copy created earlier.  See issues
            # #9775 and #15881.  Also related: #4106, #9205, and
            # #9207.

            for p in active_children():
                if p._daemonic:
                    info('calling terminate() for daemon %s', p.name)
                    p._popen.terminate()

            for p in active_children():
                info('calling join() for process %s', p.name)
                p.join()

        debug('running the remaining "atexit" finalizers')
        _run_finalizers() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:43,代碼來源:util.py

示例8: _exit_function

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def _exit_function(info=info, debug=debug, _run_finalizers=_run_finalizers,
                   active_children=active_children,
                   current_process=current_process):
    # NB: we hold on to references to functions in the arglist due to the
    # situation described below, where this function is called after this
    # module's globals are destroyed.

    global _exiting

    info('process shutting down')
    debug('running all "atexit" finalizers with priority >= 0')
    _run_finalizers(0)

    if current_process() is not None:
        # NB: we check if the current process is None here because if
        # it's None, any call to ``active_children()`` will throw an
        # AttributeError (active_children winds up trying to get
        # attributes from util._current_process).  This happens in a
        # variety of shutdown circumstances that are not well-understood
        # because module-scope variables are not apparently supposed to
        # be destroyed until after this function is called.  However,
        # they are indeed destroyed before this function is called.  See
        # issues 9775 and 15881.  Also related: 4106, 9205, and 9207.

        for p in active_children():
            if p._daemonic:
                info('calling terminate() for daemon %s', p.name)
                p._popen.terminate()

        for p in active_children():
            info('calling join() for process %s', p.name)
            p.join()

    debug('running the remaining "atexit" finalizers')
    _run_finalizers() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:37,代碼來源:util.py

示例9: get_preparation_data

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def get_preparation_data(name):
        '''
        Return info about parent needed by child to unpickle process object
        '''
        from .util import _logger, _log_to_stderr

        d = dict(
            name=name,
            sys_path=sys.path,
            sys_argv=sys.argv,
            log_to_stderr=_log_to_stderr,
            orig_dir=process.ORIGINAL_DIR,
            authkey=process.current_process().authkey,
            )

        if _logger is not None:
            d['log_level'] = _logger.getEffectiveLevel()

        if not WINEXE and not WINSERVICE and \
           not d['sys_argv'][0].lower().endswith('pythonservice.exe'):
            main_path = getattr(sys.modules['__main__'], '__file__', None)
            if not main_path and sys.argv[0] not in ('', '-c'):
                main_path = sys.argv[0]
            if main_path is not None:
                if not os.path.isabs(main_path) and \
                                          process.ORIGINAL_DIR is not None:
                    main_path = os.path.join(process.ORIGINAL_DIR, main_path)
                d['main_path'] = os.path.normpath(main_path)

        return d

    #
    # Make (Pipe)Connection picklable
    # 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:36,代碼來源:forking.py

示例10: __log__

# 需要導入模塊: from multiprocessing import process [as 別名]
# 或者: from multiprocessing.process import current_process [as 別名]
def __log__(self, msg, _type, color):
        self._check_log_file()
        msg_log = self._get_log_header() + ' ' + colored(_type, color)
        curr_process = current_process()
        curr_thread = current_thread()
        if 'Main' not in curr_process.name:
            msg_log += ' [' + curr_process.name + ']'
        if 'Main' not in curr_thread.name:
            msg_log += ' (' + curr_thread.name + ')'
        msg_log += ': ' + msg.rstrip()
        if APP_DEBUG:
            print(msg_log)
        storage.append_in_file(msg_log, APP_LOGFILE) 
開發者ID:offensive-hub,項目名稱:black-widow,代碼行數:15,代碼來源:logger.py


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