Patch.py multithreaded sfc->bmbp

bsdiff 4 releases GIL
This commit is contained in:
Fabian Dill 2020-05-02 13:01:30 +02:00
parent dd0a4e84e9
commit 815ec85da9
1 changed files with 29 additions and 26 deletions

View File

@ -93,19 +93,22 @@ if __name__ == "__main__":
address = f"{host}:{options['port']}" address = f"{host}:{options['port']}"
ziplock = threading.Lock() ziplock = threading.Lock()
print(f"Host for patches to be created is {address}") print(f"Host for patches to be created is {address}")
with concurrent.futures.ThreadPoolExecutor() as pool:
for rom in sys.argv: for rom in sys.argv:
try: try:
if rom.endswith(".sfc"): if rom.endswith(".sfc"):
print(f"Creating patch for {rom}") print(f"Creating patch for {rom}")
result = create_patch_file(rom, address) result = pool.submit(create_patch_file, rom, address)
print(f"Created patch {result}") result.add_done_callback(lambda task: print(f"Created patch {task.result()}"))
elif rom.endswith(".bmbp"): elif rom.endswith(".bmbp"):
print(f"Applying patch {rom}") print(f"Applying patch {rom}")
data, target = create_rom_file(rom) data, target = create_rom_file(rom)
print(f"Created rom {target}.") print(f"Created rom {target}.")
if 'server' in data: if 'server' in data:
print(f"Host is {data['server']}") print(f"Host is {data['server']}")
elif rom.endswith(".zip"): elif rom.endswith(".zip"):
print(f"Updating host in patch files contained in {rom}") print(f"Updating host in patch files contained in {rom}")
@ -117,7 +120,7 @@ if __name__ == "__main__":
zfw.writestr(zfinfo, data) zfw.writestr(zfinfo, data)
return zfinfo.filename return zfinfo.filename
with concurrent.futures.ThreadPoolExecutor() as pool:
futures = [] futures = []
with zipfile.ZipFile(rom, "r") as zfr: with zipfile.ZipFile(rom, "r") as zfr:
updated_zip = os.path.splitext(rom)[0] + "_updated.zip" updated_zip = os.path.splitext(rom)[0] + "_updated.zip"