当前位置: 首页>>代码示例>>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;未经允许,请勿转载。