Skip to content

Commit 431dd26

Browse files
authored
Bug fixed: devices are not properly closed. (#175) (#176)
1 parent dd0961c commit 431dd26

File tree

6 files changed

+13
-18
lines changed

6 files changed

+13
-18
lines changed

leads/__init__.py

-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
from atexit import register as _register
2-
31
from leads.config import *
42
from leads.context import *
53
from leads.data import *
64
from leads.dt import *
75
from leads.event import *
86
from leads.leads import *
97
from leads.logger import Level, L
10-
from leads.os import _thread_flags
118
from leads.plugin import *
129
from leads.registry import *
1310
from leads.sft import SFT, mark_system, read_marked_system
14-
15-
16-
@_register
17-
def _request_threads_stop() -> None:
18-
_thread_flags.active = False

leads/dt/registry.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from atexit import register as _register
12
from typing import Any as _Any, Callable as _Callable, Sequence as _Sequence
23

34
from leads.dt.controller import Controller
@@ -84,7 +85,8 @@ def get_device(tag: str) -> Device:
8485
return _devices[tag]
8586

8687

87-
def reset() -> None:
88+
@_register
89+
def release() -> None:
8890
for d in _devices.values():
8991
d.close()
9092
_devices.clear()

leads/os.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys as _sys
2+
from atexit import register as _register
23
from threading import Lock as _Lock
34
from types import FrameType as _FrameType
45

@@ -32,3 +33,8 @@ def active(self, active: bool) -> None:
3233

3334

3435
_thread_flags: _ThreadFlags = _ThreadFlags()
36+
37+
38+
@_register
39+
def _request_threads_stop() -> None:
40+
_thread_flags.active = False

leads_audio/prototype.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def _try_open_audio_device() -> None:
3131

3232
_Thread(name="sdl initializer", target=_try_open_audio_device, daemon=True).start()
3333

34-
35-
@_register
36-
def _release_resources() -> None:
37-
_close_audio()
34+
_register(_close_audio)
3835

3936

4037
class _SoundEffect(object):

leads_vec/run.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from customtkinter import set_default_color_theme as _set_default_color_theme
77

88
from leads import register_controller as _register_controller, MAIN_CONTROLLER as _MAIN_CONTROLLER, \
9-
L as _L, load_config as _load_config, register_config as _register_config, reset as _reset
9+
L as _L, load_config as _load_config, register_config as _register_config, release as _release
1010
from leads_gui import Config as _Config
1111

1212

@@ -68,7 +68,7 @@ def run(config: str,
6868
return main()
6969
else:
7070
_L.warn(f"Specified devices module ({devices}) is not available, using emulation module instead...")
71-
_reset()
71+
_release()
7272
try:
7373
from leads_emulation import SinController as _Controller
7474

leads_vec_rc/cli.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,4 @@ async def hazard() -> str:
120120
return "done"
121121

122122

123-
@register
124-
def cleanup() -> None:
125-
csv.close()
123+
register(csv.close)

0 commit comments

Comments
 (0)