From 1a4ee759b70494813666c747effb6bcaa066a348 Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Tue, 5 Aug 2014 10:39:24 -0700 Subject: [PATCH] Bug 1043144 - Don't write machc bytecode file; r=mshal When writing bytecode, Python will append "c" to the loaded filename to produce a bytecode file. Since "mach" was being imported, this resulted in the creation of a "machc" file. The implementation of imp.load_module() in CPython's import.c checks sys.dont_write_bytecode. So, we wrap imp.load_module to set this flag when importing mach. --HG-- extra : rebase_source : 248a2349663affee3920a0726e10818d57c6ff17 extra : amend_source : 221280da9963cf91975658144ff3011353852fee --- mach | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mach b/mach index 2dbdd1aa16b..2814f6fa666 100755 --- a/mach +++ b/mach @@ -92,6 +92,7 @@ if __name__ == '__main__': def fork_interpose(): import imp import os + import sys orig_find_module = imp.find_module def my_find_module(name, dirs): if name == 'mach': @@ -100,7 +101,23 @@ if __name__ == '__main__': return (f, path, ('', 'r', imp.PY_SOURCE)) return orig_find_module(name, dirs) + # Don't allow writing bytecode file for mach 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() def my_get_command_line():