mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Core: limit parallel APContainer writing (#2443)
Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
This commit is contained in:
@@ -2,11 +2,18 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
|
||||||
from typing import ClassVar, Dict, Tuple, Any, Optional, Union, BinaryIO
|
from typing import ClassVar, Dict, Tuple, Any, Optional, Union, BinaryIO
|
||||||
|
|
||||||
import bsdiff4
|
import bsdiff4
|
||||||
|
|
||||||
|
semaphore = threading.Semaphore(os.cpu_count() or 4)
|
||||||
|
|
||||||
|
del threading
|
||||||
|
del os
|
||||||
|
|
||||||
|
|
||||||
class AutoPatchRegister(type):
|
class AutoPatchRegister(type):
|
||||||
patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {}
|
patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {}
|
||||||
@@ -57,11 +64,12 @@ class APContainer:
|
|||||||
zip_file = file if file else self.path
|
zip_file = file if file else self.path
|
||||||
if not zip_file:
|
if not zip_file:
|
||||||
raise FileNotFoundError(f"Cannot write {self.__class__.__name__} due to no path provided.")
|
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) \
|
with semaphore: # TODO: remove semaphore once generate_output has a thread limit
|
||||||
as zf:
|
with zipfile.ZipFile(
|
||||||
if file:
|
zip_file, "w", self.compression_method, True, self.compression_level) as zf:
|
||||||
self.path = zf.filename
|
if file:
|
||||||
self.write_contents(zf)
|
self.path = zf.filename
|
||||||
|
self.write_contents(zf)
|
||||||
|
|
||||||
def write_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
|
def write_contents(self, opened_zipfile: zipfile.ZipFile) -> None:
|
||||||
manifest = self.get_manifest()
|
manifest = self.get_manifest()
|
||||||
|
Reference in New Issue
Block a user