コード例 #1
0
    def onModuleEncounter(
        self, module_filename, module_name, module_package, module_kind
    ):
        if (
            module_name == "multiprocessing"
            and module_package is None
            and not self.multiprocessing_added
        ):
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules

            for root_module in getRootModules():
                if root_module.isMainModule():
                    self._addSlaveMainModule(root_module)
                    break
            else:
                assert False

        if module_package == "multiprocessing" and module_name in (
            "forking",
            "spawn",
            "reduction",
        ):
            return True, "Multiprocessing plugin needs this to monkey patch it."
コード例 #2
0
def getNuitkaModules():
    """ Create a list of all modules known to Nuitka.

    Notes:
        This will be executed at most once: on the first time when a module
        is encountered and cannot be found in the recorded calls (JSON array).
    Returns:
        List of all modules.
    """
    mlist = []
    for m in getRootModules():
        if m not in mlist:
            mlist.append(m)

    for m in done_modules:
        if m not in mlist:
            mlist.append(m)

    for m in uncompiled_modules:
        if m not in mlist:
            mlist.append(m)

    for m in active_modules:
        if m not in mlist:
            mlist.append(m)

    return mlist
コード例 #3
0
    def onModuleEncounter(self, module_filename, module_name, module_kind):
        if module_name == "multiprocessing" and not self.multiprocessing_added:
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules

            for root_module in getRootModules():
                if root_module.isMainModule():
                    self._addSlaveMainModule(root_module)
                    break
            else:
                assert False

        if module_name.hasNamespace("multiprocessing"):
            return True, "Multiprocessing plugin needs this to monkey patch it."
コード例 #4
0
    def onModuleEncounter(self, module_filename, module_name, module_package,
                          module_kind):
        if module_name == "multiprocessing" and \
           module_package is None \
           and not self.multiprocessing_added:
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules

            for root_module in getRootModules():
                if root_module.isMainModule():
                    self._addSlaveMainModule(root_module)
                    break
            else:
                assert False
コード例 #5
0
    def onModuleEncounter(self, module_filename, module_name, module_package,
                          module_kind):
        if module_name == "multiprocessing" and \
           module_package is None \
           and not self.multiprocessing_added:
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules

            for root_module in getRootModules():
                if root_module.isMainModule():
                    self._addSlaveMainModule(root_module)
                    break
            else:
                assert False
コード例 #6
0
    def onModuleEncounter(self, module_filename, module_name, module_package,
                          module_kind):
        if module_name == "multiprocessing" and \
           module_package is None \
           and not self.multiprocessing_added:
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules, addRootModule
            from nuitka.tree.Building import CompiledPythonModule, readSourceCodeFromFilename, createModuleTree

            for root_module in getRootModules():
                if root_module.isMainModule():
                    # First, build the module node and then read again from the
                    # source code.

                    slave_main_module = CompiledPythonModule(
                        name         = "__parents_main__",
                        package_name = None,
                        source_ref   = root_module.getSourceReference()
                    )

                    source_code = readSourceCodeFromFilename(
                        "__parents_main__",
                        root_module.getFilename()
                    )

                    # For the call stack, this may look bad or different to what
                    # CPython does. Using the "__import__" built-in to not spoil
                    # or use the module namespace.
                    source_code += """
__import__("sys").modules["__main__"] = __import__("sys").modules[__name__]
__import__("multiprocessing.forking").forking.main()"""

                    createModuleTree(
                        module      = slave_main_module,
                        source_ref  = root_module.getSourceReference(),
                        source_code = source_code,
                        is_main     = False
                    )

                    # This is an alternative entry point of course.
                    addRootModule(slave_main_module)

                    break
            else:
                assert False
コード例 #7
0
    def onModuleEncounter(self, module_filename, module_name, module_package,
                          module_kind):
        if (module_name == "multiprocessing" and module_package is None
                and not self.multiprocessing_added):
            self.multiprocessing_added = True

            from nuitka.ModuleRegistry import getRootModules

            for root_module in getRootModules():
                if root_module.isMainModule():
                    self._addSlaveMainModule(root_module)
                    break
            else:
                assert False

        if module_package == "multiprocessing" and module_name in (
                "forking",
                "spawn",
                "reduction",
        ):
            return True, "Multiprocessing plugin needs this to monkey patch it."