| 905 | remove_bytecode(self.module_path) |
| 906 | |
| 907 | def update_lib(self): |
| 908 | self.lib_count += 1 |
| 909 | for modname in list(sys.modules): |
| 910 | if modname.startswith(self.module_name): |
| 911 | del sys.modules[modname] |
| 912 | with salt.utils.files.fopen(self.lib_path, "wb") as fh: |
| 913 | fh.write( |
| 914 | salt.utils.stringutils.to_bytes( |
| 915 | submodule_lib_template.format(count=self.lib_count) |
| 916 | ) |
| 917 | ) |
| 918 | fh.flush() |
| 919 | os.fsync(fh.fileno()) # flush to disk |
| 920 | |
| 921 | # pyc files don't like it when we change the original quickly |
| 922 | # since the header bytes only contain the timestamp (granularity of seconds) |
| 923 | # TODO: don't write them? Is *much* slower on re-load (~3x) |
| 924 | # https://docs.python.org/2/library/sys.html#sys.dont_write_bytecode |
| 925 | remove_bytecode(self.lib_path) |
| 926 | |
| 927 | def rm_lib(self): |
| 928 | for modname in list(sys.modules): |