Exemplo n.º 1
0
        def fork_interpose():
            import imp
            import os
            import sys
            orig_find_module = imp.find_module
            def my_find_module(name, dirs):
                if name == main_module_name:
                    path = os.path.join(dirs[0], main_file_name)
                    f = open(path)
                    return (f, path, ('', 'r', imp.PY_SOURCE))
                return orig_find_module(name, dirs)

            # Don't allow writing bytecode file for the main module.
            orig_load_module = imp.load_module
            def my_load_module(name, file, path, description):
                # multiprocess.forking invokes imp.load_module manually and
                # hard-codes the name __parents_main__ as the module name.
                if name == '__parents_main__':
                    old_bytecode = sys.dont_write_bytecode
                    sys.dont_write_bytecode = True
                    try:
                        return orig_load_module(name, file, path, description)
                    finally:
                        sys.dont_write_bytecode = old_bytecode

                return orig_load_module(name, file, path, description)

            imp.find_module = my_find_module
            imp.load_module = my_load_module
            from multiprocessing.forking import main; main()
Exemplo n.º 2
0
        def fork_interpose():
            import imp
            import os
            import sys
            orig_find_module = imp.find_module

            def my_find_module(name, dirs):
                if name == main_module_name:
                    path = os.path.join(dirs[0], main_file_name)
                    f = open(path)
                    return (f, path, ('', 'r', imp.PY_SOURCE))
                return orig_find_module(name, dirs)

            # Don't allow writing bytecode file for the main module.
            orig_load_module = imp.load_module

            def my_load_module(name, file, path, description):
                # multiprocess.forking invokes imp.load_module manually and
                # hard-codes the name __parents_main__ as the module name.
                if name == '__parents_main__':
                    old_bytecode = sys.dont_write_bytecode
                    sys.dont_write_bytecode = True
                    try:
                        return orig_load_module(name, file, path, description)
                    finally:
                        sys.dont_write_bytecode = old_bytecode

                return orig_load_module(name, file, path, description)

            imp.find_module = my_find_module
            imp.load_module = my_load_module
            from multiprocessing.forking import main
            main()
Exemplo n.º 3
0
    if name == main_module_name:
        path = os.path.join(dirs[0], main_file_name)
        f = open(path)
        return (f, path, ('', 'r', imp.PY_SOURCE))
    return orig_find_module(name, dirs)


# Don't allow writing bytecode file for the main module.
orig_load_module = imp.load_module


def my_load_module(name, file, path, description):
    # multiprocess.forking invokes imp.load_module manually and
    # hard-codes the name __parents_main__ as the module name.
    if name == '__parents_main__':
        old_bytecode = sys.dont_write_bytecode
        sys.dont_write_bytecode = True
        try:
            return orig_load_module(name, file, path, description)
        finally:
            sys.dont_write_bytecode = old_bytecode

    return orig_load_module(name, file, path, description)


imp.find_module = my_find_module
imp.load_module = my_load_module
from multiprocessing.forking import main

main()
Exemplo n.º 4
0
Arquivo: chost.py Projeto: shvar/redfs
#!/usr/bin/python
"""Host loader."""
import sys

if sys.platform == 'win32':
    sys.path.extend(['libs', 'libs/modules.dat'])
elif sys.platform.startswith('linux'):
    sys.path.extend(['/usr/share/pyshared/calathi'])

if __name__ == '__main__':
    if len(sys.argv) == 5 and sys.argv[1:4] == ['-c',
                                                'from multiprocessing.forking import main; main()',
                                                '--multiprocessing-fork']:
        from multiprocessing.forking import main; main()
    else:
        import uhostcli
        uhostcli.main()