Skip to content

Commit

Permalink
Core: limit parallel APContainer writing (ArchipelagoMW#2443)
Browse files Browse the repository at this point in the history
Co-authored-by: black-sliver <[email protected]>
  • Loading branch information
2 people authored and FlySniper committed Nov 14, 2023
1 parent 1b7336c commit a712643
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions worlds/Files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import json
import zipfile
import os
import threading

from typing import ClassVar, Dict, Tuple, Any, Optional, Union, BinaryIO

import bsdiff4

semaphore = threading.Semaphore(os.cpu_count() or 4)

del threading
del os


class AutoPatchRegister(type):
patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {}
Expand Down Expand Up @@ -57,11 +64,12 @@ def write(self, file: Optional[Union[str, BinaryIO]] = None) -> None:
zip_file = file if file else self.path
if not zip_file:
raise FileNotFoundError(f"Cannot write {self.__class__.__name__} due to no path provided.")
with zipfile.ZipFile(zip_file, "w", self.compression_method, True, self.compression_level) \
as zf:
if file:
self.path = zf.filename
self.write_contents(zf)
with semaphore: # TODO: remove semaphore once generate_output has a thread limit
with zipfile.ZipFile(
zip_file, "w", self.compression_method, True, self.compression_level) as zf:
if file:
self.path = zf.filename
self.write_contents(zf)

def write_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
manifest = self.get_manifest()
Expand Down

0 comments on commit a712643

Please sign in to comment.