From 680ebfc16b2d37bbcf066573be13ec0cf39ff0a0 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Wed, 2 Sep 2026 16:16:57 +0800 Subject: [PATCH] Improve Python code readability Signed-off-by: Loren Eteval --- Furious/Application/DesktopApplication.py | 3 ++- Furious/Service/EndpointInfoService.py | 3 +++ Furious/Service/ProfileTesting.py | 3 +++ Furious/Service/SubscriptionManager.py | 2 -- Furious/Service/TrafficStatsManager.py | 6 ++++++ tests/test_connection_startup_async.py | 1 + tests/test_profile_test_jobs.py | 2 ++ tests/test_subscription_manager.py | 1 + 8 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Furious/Application/DesktopApplication.py b/Furious/Application/DesktopApplication.py index 18c2684..df24c16 100644 --- a/Furious/Application/DesktopApplication.py +++ b/Furious/Application/DesktopApplication.py @@ -1013,7 +1013,6 @@ class DesktopApplication(ApplicationRunner, SingletonApplication): return ApplicationRunner.ExitCode.ExitSuccess.value pluginRegistry = self.addEnviron() - self._cleanupStack.register('plugins', pluginRegistry.shutdown) try: @@ -1029,6 +1028,7 @@ class DesktopApplication(ApplicationRunner, SingletonApplication): self._cleanupStack.register( 'mixin-owned resources', Mixins.CleanupOnExit.cleanupAll ) + self._initializeControllers() self._cleanupStack.register('controllers', self._cleanupControllers) @@ -1041,6 +1041,7 @@ class DesktopApplication(ApplicationRunner, SingletonApplication): self._cleanupStack.register('theme detection', self._stopThemeDetection) self.aboutToQuit.connect(self.cleanup) + self._initializeSystemIntegration() self._initializeUI() diff --git a/Furious/Service/EndpointInfoService.py b/Furious/Service/EndpointInfoService.py index 329a2bc..457c033 100644 --- a/Furious/Service/EndpointInfoService.py +++ b/Furious/Service/EndpointInfoService.py @@ -387,9 +387,12 @@ class EndpointInfoService(QtCore.QObject): self._cached = False self._requestInFlight = False self._countryHint = '' + self.httpClient.cancelAll() + self._setState(EndpointInfoState.Loading) self._publishResult(EndpointInfo()) + self._startLookup() def requestIfNeeded(self): diff --git a/Furious/Service/ProfileTesting.py b/Furious/Service/ProfileTesting.py index e4e04a0..c894896 100644 --- a/Furious/Service/ProfileTesting.py +++ b/Furious/Service/ProfileTesting.py @@ -583,6 +583,7 @@ class _LatencyScheduler(QtCore.QObject): self.discardTcpingJobs( lambda job: job.target.subscriptionSource in subscriptionIds ) + self.scheduleDrain() def discardTcpingJobs(self, predicate): @@ -1391,6 +1392,7 @@ class ProfileTestManager(QtCore.QObject): def reconcileProfiles(self): """Refresh current identity once and proactively invalidate stale work.""" self._targets = _currentTargets(self._profilesProvider()) + self._latencyScheduler.reconcileProfiles() self._serialDownloadScheduler.reconcileProfiles() self._concurrentDownloadScheduler.reconcileProfiles() @@ -1419,6 +1421,7 @@ class ProfileTestManager(QtCore.QObject): return self._shuttingDown = True + self._latencyScheduler.shutdown() self._serialDownloadScheduler.cancelAll() self._concurrentDownloadScheduler.cancelAll() diff --git a/Furious/Service/SubscriptionManager.py b/Furious/Service/SubscriptionManager.py index c969d49..4565ecb 100644 --- a/Furious/Service/SubscriptionManager.py +++ b/Furious/Service/SubscriptionManager.py @@ -552,7 +552,6 @@ class SubscriptionManager(HttpGetManager): jobId = getattr(outcome, 'jobId', -1) self._preparationJobs.pop(jobId, None) - fallbackPayload = self._preparationPayloads.pop(jobId, None) context = getattr(outcome, 'context', {}) @@ -1089,7 +1088,6 @@ class SubscriptionManager(HttpGetManager): operations = [] self._nextBatchId += 1 - batchId = self._nextBatchId for unique, subscription in batch: diff --git a/Furious/Service/TrafficStatsManager.py b/Furious/Service/TrafficStatsManager.py index a097f54..3bd3fa0 100644 --- a/Furious/Service/TrafficStatsManager.py +++ b/Furious/Service/TrafficStatsManager.py @@ -347,10 +347,13 @@ class TrafficStatsManager( """Stop statistics work without changing the connection lifecycle.""" self._sampleTimer.stop() self._generation += 1 + self._cancelCurrentQuery() self._monitor = None + self._resetSamples() self._beginConnectionUsage() + self.statisticsUnavailable.emit() @QtCore.Slot(bool) @@ -514,10 +517,13 @@ class TrafficStatsManager( self._connected = False self._sampleTimer.stop() self._generation += 1 + self._cancelCurrentQuery() self._monitor = None + self._resetSamples() self._beginConnectionUsage() + self.statisticsUnavailable.emit() def cleanup(self): diff --git a/tests/test_connection_startup_async.py b/tests/test_connection_startup_async.py index bcdd4fc..cd2908c 100644 --- a/tests/test_connection_startup_async.py +++ b/tests/test_connection_startup_async.py @@ -583,6 +583,7 @@ class ConnectionStartupAsyncTest(TestCase): 'Global', deepcopy=False, ) + succeeded = [] operation.succeeded.connect(succeeded.append) diff --git a/tests/test_profile_test_jobs.py b/tests/test_profile_test_jobs.py index b6cc800..fc552ae 100644 --- a/tests/test_profile_test_jobs.py +++ b/tests/test_profile_test_jobs.py @@ -831,12 +831,14 @@ class ProfileTestServiceTest(unittest.TestCase): activeLatency.finish('stale') processQtEvents() + self.assertEqual(retained.metadata.latency, '') self.assertEqual(len(pool.started), 2) otherLatency = pool.started[1] otherLatency.finish('9ms') processQtEvents() + otherDownload = next( worker for worker in _ControlledDownloadWorker.instances diff --git a/tests/test_subscription_manager.py b/tests/test_subscription_manager.py index 0da4cd8..ed9142f 100644 --- a/tests/test_subscription_manager.py +++ b/tests/test_subscription_manager.py @@ -1073,6 +1073,7 @@ class SubscriptionManagerTest(TestCase): self.assertTrue(started.wait(2)) handled = [] + QtCore.QTimer.singleShot(0, lambda: handled.append(True)) processQtEvents(1)