#๐Ÿ”’ progaram stucks on multiprocessing.Process.start()

8 messages ยท Page 1 of 1 (latest)

toxic sleet
#

As far I know .start() should start process immediately and go next lines of code.
But after starting some processes program stucks on Process.start() line until some of other previously started processes finished. My system has 32 threads. At the moment of stuck on . start() method, already started processes number is around 10.
How to fix this?
What is reason of this?
Is it Python 3.12 bug or I just don't know smth?
Checked with prints what line before is executed, line after is not.

        while processed_mods_count < mods_to_deobf_count:
            if len(self.deobf_threads) < allocated_threads_count and started_mods_count < mods_to_deobf_count:
                mod_name = mods_iter.__next__()
                logging.info(f'Started deobfuscation of {mod_name}')
                deobf_thread = DeobfuscationThread(os.path.join('tmp', 'mods', mod_name),
                                                   started_mods_count, self.serialized_widgets)
                started_mods_count += 1
                self.deobf_threads.append(deobf_thread)
                deobf_thread.start() # this line

full code:
https://github.com/KostromDan/Mods-Decompiler-GUI/blob/tk-to-PySide6-rewrite/MDGLogic/DeobfuscationMainThread.py#L70

timber irisBOT
#

@toxic sleet

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

#

MDGLogic/DeobfuscationMainThread.py line 70

deobf_thread.start()```
toxic sleet
#

program stucks on multiprocessing.Process.start()

#

Thread code:

import multiprocessing
import os.path
import shutil
import subprocess
import time
from pathlib import Path

from MDGLogic.MdkInitialisationThread import unzip_and_patch_mdk
from MDGUtil.SubprocessKiller import kill_subprocess


class DeobfuscationThread(multiprocessing.Process):

    def __init__(self, mod_path: str, thread_number: int, serialized_widgets: dict):
        super().__init__()
        self.mod_path = mod_path
        self.thread_number = thread_number
        self.serialized_widgets = serialized_widgets
        self.is_cmd_started = multiprocessing.Value('b', False)
        self.kill_cmd = multiprocessing.Value('b', False)
        self.success = multiprocessing.Value('b', False)

    def run(self):
        current_mdk_path = f'tmp/deobfuscation_MDKs/mdk_{self.thread_number}'
        deobfed_folder_name = f'local_MDG_{self.thread_number}'
        unzip_and_patch_mdk(self.serialized_widgets['mdk_path_line_edit']['text'],
                            current_mdk_path,
                            deobfed_folder_name,
                            True)
        shutil.copy(self.mod_path, os.path.join(current_mdk_path, 'libs'))
        deobfed_mods_path = os.path.join(os.path.expanduser('~'),
                                         '.gradle',
                                         'caches',
                                         'forge_gradle',
                                         'deobf_dependencies',
                                         deobfed_folder_name)
        self.cmd = subprocess.Popen(["gradlew.bat", "compileJava"], cwd=current_mdk_path, shell=True)
        with self.is_cmd_started.get_lock():
            self.is_cmd_started.value = True
        while self.cmd.poll() is None:
            time.sleep(0.1)
            path_to_jar_list = list(Path(deobfed_mods_path).rglob('*.jar'))
            if path_to_jar_list:
                path_to_jar = os.path.join(path_to_jar_list[0])
                cur_size = os.path.getsize(path_to_jar)
                old_size = -1
                while cur_size == 0 or cur_size > old_size:
                    old_size = cur_size
                    cur_size = os.path.getsize(path_to_jar)
                    time.sleep(0.1)
                # time_finished=datetime.datetime.now()
                # while self.cmd.poll() is None:
                #     pass
                # print(f'Time saved: {datetime.datetime.now()-time_finished}.')

            if path_to_jar_list or self.kill_cmd.value:
                kill_subprocess(self.cmd.pid)

            if self.kill_cmd.value:
                return

        if not path_to_jar_list:
            return

        mod_original_name = os.path.basename(self.mod_path)
        mod_new_mapped_name = mod_original_name.rstrip('.jar') + '_mapped_official.jar'
        new_jar_path = os.path.join(os.path.dirname(path_to_jar), mod_new_mapped_name)
        try:
            os.rename(path_to_jar,
                      new_jar_path)
        except FileExistsError:
            pass
        shutil.copy(new_jar_path, 'result/deobfuscated_mods')
        with self.success.get_lock():
            self.success.value = True

    def is_success(self):
        return self.success.value

    def terminate(self):
        with self.kill_cmd.get_lock():
            self.kill_cmd.value = True
        if not self.is_cmd_started.value:
            try:
                super().kill()
            except AttributeError:
                pass
#

Is it related with usage of subprocess?

timber irisBOT
#

@toxic sleet

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.