commit 76aa952f922b49b4c0d35187e699c3e454bdc7f7
parent a3fa1b960e1152026abb81a0825715c9c583c247
Author: Paco Esteban <paco@e1e0.net>
Date: Sun, 24 Oct 2021 11:51:12 +0200
move threading to helpers to make it more general
Diffstat:
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/subclient/helpers.py b/subclient/helpers.py
@@ -1,4 +1,5 @@
import os
+import threading
import time
HOME = os.environ.get('HOME')
@@ -38,3 +39,22 @@ def get_config_file():
raise FileNotFoundError(f'Config file {config_file} does not exist')
return config_file
+
+
+class Job(threading.Thread):
+ def __init__(self, interval, execute, *args, **kwargs):
+ threading.Thread.__init__(self)
+ self.daemon = False
+ self.stopped = threading.Event()
+ self.interval = interval
+ self.execute = execute
+ self.args = args
+ self.kwargs = kwargs
+
+ def stop(self):
+ self.stopped.set()
+ self.join()
+
+ def run(self):
+ while not self.stopped.wait(self.interval.total_seconds()):
+ self.execute(*self.args, **self.kwargs)
diff --git a/subclient/subclient.py b/subclient/subclient.py
@@ -4,7 +4,6 @@
import configparser
import curses
import sys
-import threading
from datetime import timedelta
from subclient import subsonic
from subclient import player
@@ -14,25 +13,6 @@ from subclient import helpers
__version__ = 'v0.0.1'
-class Updater(threading.Thread):
- def __init__(self, interval, execute, *args, **kwargs):
- threading.Thread.__init__(self)
- self.daemon = False
- self.stopped = threading.Event()
- self.interval = interval
- self.execute = execute
- self.args = args
- self.kwargs = kwargs
-
- def stop(self):
- self.stopped.set()
- self.join()
-
- def run(self):
- while not self.stopped.wait(self.interval.total_seconds()):
- self.execute(*self.args, **self.kwargs)
-
-
class SubClient:
UP = -1
DOWN = 1
@@ -64,7 +44,7 @@ class SubClient:
self.width = 0
self.listwin_height = 0
self.infowin_height = 0
- self.info_updater = Updater(timedelta(seconds=1), self.update_info)
+ self.info_updater = helpers.Job(timedelta(seconds=1), self.update_info)
self.init_curses()
self.nav_list = self.subsonic.get_artists()