增加超时计智

This commit is contained in:
wangsong 2021-10-18 17:27:57 +08:00
parent b35a598a65
commit cf78342db5
2 changed files with 35 additions and 2 deletions

View File

@ -15,7 +15,11 @@ from aptdaemon.enums import (EXIT_SUCCESS,
from SystemUpdater.backend import InstallBackend
import logging
from gettext import gettext as _
import dbus
import dbus,time
from gi.repository import GLib
APTDAEMON_IDLE_CHECK_INTERVAL = 8
APTDAEMON_IDLE_TIMEOUT = 2 * 10
class InstallBackendAptdaemon(InstallBackend):
"""Makes use of aptdaemon to refresh the cache and to install updates."""
@ -28,9 +32,37 @@ class InstallBackendAptdaemon(InstallBackend):
self.trans_failed_msg = None
self.trans_progress = 0
self.static_progress = 0
self.trans_status = ''
self.details = ''
self.last_action_timestamp = time.time()
if self.action == self.ACTION_INSTALL:
logging.info("timeout_add_seconds init")
GLib.timeout_add_seconds(APTDAEMON_IDLE_CHECK_INTERVAL,
self._check_for_inactivity)
def _check_for_inactivity(self):
"""Shutdown the daemon if it has been inactive for time specified
in APTDAEMON_IDLE_TIMEOUT.
"""
if self.window_main.is_upgrading == False:
logging.error("quit")
return False
if self.trans_progress != self.static_progress:
self.static_progress = self.trans_progress
self.last_action_timestamp = time.time()
logging.debug("Checking for inactivity")
timestamp = self.last_action_timestamp
if (time.time() - timestamp > APTDAEMON_IDLE_TIMEOUT):
logging.info("Quitting due to inactivity")
self.window_main.dbusController.Quit(None)
return False
return True
@inline_callbacks
def update(self):
"""刷新包cache"""
@ -103,7 +135,9 @@ class InstallBackendAptdaemon(InstallBackend):
def _on_progress_changed(self, trans,progress,action):
if progress == 101:
return
self.trans_progress = progress
if action == self.ACTION_UPDATE:
self.window_main.dbusController.UpdateDetectStatusChanged(self.trans_progress,self.trans_status)
else:

View File

@ -18,7 +18,6 @@ from SystemUpdater.Core.utils import (
)
from ..Core.Database import MODE_UPGRADEPARTIAL,MODE_UPGRADEALL
class NowUpgradePara:
"""
Represent the (potentially partial) results of an unattended-upgrades