Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partially initialized module #664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/subsearch/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import ctypes
import threading
import time
from pathlib import Path
from typing import Callable
from typing import Any, Callable

from subsearch.globals import decorators, thread_handle
from subsearch.globals import decorators
from subsearch.globals.constants import APP_PATHS, DEVICE_INFO, FILE_PATHS, VIDEO_FILE
from subsearch.globals.dataclasses import Subtitle
from subsearch.gui import screen_manager, system_tray
Expand Down Expand Up @@ -99,7 +100,7 @@ def _create_threads(self, *tasks) -> None:
for thread_count, target in enumerate(tasks, start=1):
func_name = str(target.__name__).split("_")[-1]
name = f"thread_{thread_count}_{func_name}"
task_thread = thread_handle.CreateThread(target=target, name=name)
task_thread = CreateThread(target=target, name=name)
task_thread.start()
task_thread.join()

Expand Down Expand Up @@ -216,3 +217,34 @@ def core_on_exit(self) -> None:
input("Enter to exit")
except KeyboardInterrupt:
pass


class CreateThread(threading.Thread):
def __init__(self, *args, **kwargs) -> None:
self._target = None
self._args = ()
self._kwargs = {} # type: ignore
super().__init__(*args, **kwargs)
self.exception = None
self.return_value = None
assert self._target

def run(self) -> None:
try:
io_log.log.stdout(f"Thread {self.name} started", level="debug", print_allowed=False)
if self._target:
self.return_value = self._target(*self._args, **self._kwargs)
except Exception as e:
self.exception = e # type: ignore
finally:
del self._target, self._args, self._kwargs

def join(self, timeout=None) -> Any:
super().join(timeout)
if self.exception:
msg = f"\nError occurred in thread {self.name}\n\tTraceback (most recent call last):\n\t\t{self.exception}"
io_log.log.stdout(msg, level="error", print_allowed=False)
raise self.exception
else:
io_log.log.stdout(f"Thread {self.name} finnished", level="debug", print_allowed=False)
return self.return_value
35 changes: 0 additions & 35 deletions src/subsearch/globals/thread_handle.py

This file was deleted.

Loading