Beispiel #1
0
def _freeze_support():
    # we want to catch the two processes that are spawned by the
    # multiprocessing code:
    # - the semaphore tracker, which cleans up named semaphores in
    #   the spawn multiprocessing mode
    # - the fork server, which keeps track of worker processes in
    #   forkserver mode.
    # both of these processes are started by spawning a new copy of the
    # running executable, passing it the flags from
    # _args_from_interpreter_flags and then "-c" and an import statement.
    # look for those flags and the import statement, then exec() the
    # code ourselves.

    if len(sys.argv) >= 2 and \
            set(sys.argv[1:-2]) == set(_args_from_interpreter_flags()) and \
            sys.argv[-2] == '-c' and \
            (sys.argv[-1].startswith('from multiprocessing.semaphore_tracker import main') or \
             sys.argv[-1].startswith('from multiprocessing.forkserver import main')):
        exec(sys.argv[-1])
        sys.exit()

    if spawn.is_forking(sys.argv):
        kwds = {}
        for arg in sys.argv[2:]:
            name, value = arg.split('=')
            if value == 'None':
                kwds[name] = None
            else:
                kwds[name] = int(value)
        spawn.spawn_main(**kwds)
        sys.exit()
Beispiel #2
0
    def freeze_support(self):
        #: Prevent the "spawn" subprocess creation routines from reading the __main__ method of the target module.
        multiprocessing.process.ORIGINAL_DIR = None

        #: Define a function for determining if the interpreter is executing inlined Python code.
        def _is_executing_inline_python_code():
            return \
                len(sys.argv) >= 2 and \
                set(sys.argv[1:-2]) == set(_args_from_interpreter_flags()) and sys.argv[-2] == '-c'

        if _is_executing_inline_python_code():
            code = sys.argv[-1]
            if code.startswith(self.SIG_STARTING_FORK_SERVER):
                exec(sys.argv[-1])
                sys.exit()

        if spawn.is_forking(sys.argv):
            kwargs = {}
            for arg in sys.argv[2:]:
                k, v = arg.split('=')
                if v == 'None':
                    kwargs[k] = None
                else:
                    kwargs[k] = int(v)

            spawn.spawn_main(**kwargs)
            sys.exit()
    def _freeze_support():
        if 'multiprocessing.semaphore_tracker' in sys.argv[-1]:
            m = re.compile('.*main\((\d+)\)$').match(sys.argv[-1])
            fd = int(m.group(1))
            import multiprocessing.semaphore_tracker
            multiprocessing.semaphore_tracker.main(fd)
            sys.exit()

        if spawn.is_forking(sys.argv):
            kwds = {}
            for arg in sys.argv[2:]:
                name, value = arg.split('=')
                if value == 'None':
                    kwds[name] = None
                else:
                    kwds[name] = int(value)
            spawn.spawn_main(**kwds)
            sys.exit()
def _freeze_support():
    if 'multiprocessing.semaphore_tracker' in sys.argv[-1]:
        m = re.compile('.*main\((\d+)\)$').match(sys.argv[-1])
        fd = int(m.group(1))
        import multiprocessing.semaphore_tracker
        multiprocessing.semaphore_tracker.main(fd)
        sys.exit()

    if spawn.is_forking(sys.argv):
        kwds = {}
        for arg in sys.argv[2:]:
            name, value = arg.split('=')
            if value == 'None':
                kwds[name] = None
            else:
                kwds[name] = int(value)
        spawn.spawn_main(**kwds)
        sys.exit()