1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

lvmdbusd: Use timer instead of thread

We had a thread sitting around for cleaning up other processes, changed to
a periodic timer task.
This commit is contained in:
Tony Asleson 2016-11-01 17:42:14 -05:00
parent 68e7d34965
commit c8e8439b3d
2 changed files with 11 additions and 15 deletions

View File

@ -10,7 +10,6 @@
import threading
import subprocess
from . import cfg
import time
from .cmdhandler import options_to_cli_args
import dbus
from .utils import pv_range_append, pv_dest_ranges, log_error, log_debug
@ -112,17 +111,15 @@ def merge(interface_name, lv_uuid, lv_name, merge_options, job_state):
def background_reaper():
while cfg.run.value != 0:
with _rlock:
num_threads = len(_thread_list) - 1
if num_threads >= 0:
for i in range(num_threads, -1, -1):
_thread_list[i].join(0)
if not _thread_list[i].is_alive():
log_debug("Removing thread: %s" % _thread_list[i].name)
_thread_list.pop(i)
time.sleep(3)
with _rlock:
num_threads = len(_thread_list) - 1
if num_threads >= 0:
for i in range(num_threads, -1, -1):
_thread_list[i].join(0)
if not _thread_list[i].is_alive():
log_debug("Reaping thread: %s" % _thread_list[i].name)
_thread_list.pop(i)
return True
def background_execute(command, background_job):

View File

@ -156,9 +156,8 @@ def main():
cfg.db = lvmdb.DataStore(cfg.args.use_json)
# Start up thread to monitor pv moves
thread_list.append(
threading.Thread(target=background_reaper, name="pv_move_reaper"))
# Periodically call function to reap threads that are created
GLib.timeout_add(5000, background_reaper)
# Using a thread to process requests.
thread_list.append(threading.Thread(target=process_request))