python process._sbootstrap()/ .start()

时间:2010-11-23 21:05:34

标签: python process multiprocessing bootstrapping

python的multiprocessing.Process的start()方法如何工作。特别是,Process._bootstrap()&是否有任何文档。如果是这样的话?

2 个答案:

答案 0 :(得分:0)

我不确定你需要弄乱_bootstrap。如果您正在寻找有关如何使用Process类的基本想法,我会看一下:

答案 1 :(得分:0)

以下是代码,直接来自我的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