简体   繁体   English

python process._sbootstrap()/ .start()

[英]python process._sbootstrap() / .start()

How does python's multiprocessing.Process's start() method work. python的multiprocessing.Process的start()方法如何工作。 In particular, is there any documentation for Process._bootstrap() & if so where? 特别是,是否有有关Process._bootstrap()的任何文档?

I'm not sure you need to mess with _bootstrap. 我不确定您是否需要使用_bootstrap。 If you are looking for a basic idea on how to use the Process class, I would take a look at: 如果您正在寻找有关如何使用Process类的基本想法,那么我来看看:

Here's the code, straight from my Python 2.7 install: 这是直接来自我的Python 2.7安装的代码:

def _bootstrap(self):
    from . import util
    global _current_process

    try:
        self._children = set()
        self._counter = itertools.count(1)
        try:
            sys.stdin.close()
            sys.stdin = open(os.devnull)
        except (OSError, ValueError):
            pass
        _current_process = self
        util._finalizer_registry.clear()
        util._run_after_forkers()
        util.info('child process calling self.run()')
        try:
            self.run()
            exitcode = 0
        finally:
            util._exit_function()
    except SystemExit, e:
        if not e.args:
            exitcode = 1
        elif type(e.args[0]) is int:
            exitcode = e.args[0]
        else:
            sys.stderr.write(e.args[0] + '\n')
            sys.stderr.flush()
            exitcode = 1
    except:
        exitcode = 1
        import traceback
        sys.stderr.write('Process %s:\n' % self.name)
        sys.stderr.flush()
        traceback.print_exc()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM