From 2fb41341c94fe1d53c2c9d48e74e163c725c5857 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Wed, 2 Feb 2022 00:21:54 -0500 Subject: [PATCH] [Core] Convert inlineCallbacks to maybe_coroutine Make logging functions synchronous. They were not calling any async functions, and wrapping them in maybe_coroutine caused reactor to be imported before gtkui could install the gtk reactor. Closes: https://github.com/deluge-torrent/deluge/pull/353 --- deluge/core/core.py | 14 +++++++------- deluge/core/torrentmanager.py | 9 +++++---- deluge/log.py | 24 ++++++++---------------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index 1090b0f2a..398e3584a 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -38,7 +38,7 @@ from deluge.core.pluginmanager import PluginManager from deluge.core.preferencesmanager import PreferencesManager from deluge.core.rpcserver import export from deluge.core.torrentmanager import TorrentManager -from deluge.decorators import deprecated +from deluge.decorators import deprecated, maybe_coroutine from deluge.error import ( AddTorrentError, DelugeError, @@ -498,13 +498,13 @@ class Core(component.Component): """ - @defer.inlineCallbacks - def add_torrents(): + @maybe_coroutine + async def add_torrents(): errors = [] last_index = len(torrent_files) - 1 for idx, torrent in enumerate(torrent_files): try: - yield self.add_torrent_file_async( + await self.add_torrent_file_async( torrent[0], torrent[1], torrent[2], save_state=idx == last_index ) except AddTorrentError as ex: @@ -769,14 +769,14 @@ class Core(component.Component): ) @export - @defer.inlineCallbacks - def get_torrents_status(self, filter_dict, keys, diff=False): + @maybe_coroutine + async def get_torrents_status(self, filter_dict, keys, diff=False): """ returns all torrents , optionally filtered by filter_dict. """ all_keys = not keys torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict) - status_dict, plugin_keys = yield self.torrentmanager.torrents_status_update( + status_dict, plugin_keys = await self.torrentmanager.torrents_status_update( torrent_ids, keys, diff=diff ) # Ask the plugin manager to fill in the plugin keys diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py index 1bc05365c..ef1cabe6b 100644 --- a/deluge/core/torrentmanager.py +++ b/deluge/core/torrentmanager.py @@ -33,6 +33,7 @@ from deluge.common import ( from deluge.configmanager import ConfigManager, get_config_dir from deluge.core.authmanager import AUTH_LEVEL_ADMIN from deluge.core.torrent import Torrent, TorrentOptions, sanitize_filepath +from deluge.decorators import maybe_coroutine from deluge.error import AddTorrentError, InvalidTorrentError from deluge.event import ( ExternalIPEvent, @@ -247,8 +248,8 @@ class TorrentManager(component.Component): self.save_resume_data_timer.start(190, False) self.prev_status_cleanup_loop.start(10) - @defer.inlineCallbacks - def stop(self): + @maybe_coroutine + async def stop(self): # Stop timers if self.save_state_timer.running: self.save_state_timer.stop() @@ -260,11 +261,11 @@ class TorrentManager(component.Component): self.prev_status_cleanup_loop.stop() # Save state on shutdown - yield self.save_state() + await self.save_state() self.session.pause() - result = yield self.save_resume_data(flush_disk_cache=True) + result = await self.save_resume_data(flush_disk_cache=True) # Remove the temp_file to signify successfully saved state if result and os.path.isfile(self.temp_file): os.remove(self.temp_file) diff --git a/deluge/log.py b/deluge/log.py index 6ce6c2df6..9ac0e27d5 100644 --- a/deluge/log.py +++ b/deluge/log.py @@ -51,39 +51,31 @@ class Logging(LoggingLoggerClass): ) ) - @defer.inlineCallbacks def garbage(self, msg, *args, **kwargs): - yield LoggingLoggerClass.log(self, 1, msg, *args, **kwargs) + LoggingLoggerClass.log(self, 1, msg, *args, **kwargs) - @defer.inlineCallbacks def trace(self, msg, *args, **kwargs): - yield LoggingLoggerClass.log(self, 5, msg, *args, **kwargs) + LoggingLoggerClass.log(self, 5, msg, *args, **kwargs) - @defer.inlineCallbacks def debug(self, msg, *args, **kwargs): - yield LoggingLoggerClass.debug(self, msg, *args, **kwargs) + LoggingLoggerClass.debug(self, msg, *args, **kwargs) - @defer.inlineCallbacks def info(self, msg, *args, **kwargs): - yield LoggingLoggerClass.info(self, msg, *args, **kwargs) + LoggingLoggerClass.info(self, msg, *args, **kwargs) - @defer.inlineCallbacks def warning(self, msg, *args, **kwargs): - yield LoggingLoggerClass.warning(self, msg, *args, **kwargs) + LoggingLoggerClass.warning(self, msg, *args, **kwargs) warn = warning - @defer.inlineCallbacks def error(self, msg, *args, **kwargs): - yield LoggingLoggerClass.error(self, msg, *args, **kwargs) + LoggingLoggerClass.error(self, msg, *args, **kwargs) - @defer.inlineCallbacks def critical(self, msg, *args, **kwargs): - yield LoggingLoggerClass.critical(self, msg, *args, **kwargs) + LoggingLoggerClass.critical(self, msg, *args, **kwargs) - @defer.inlineCallbacks def exception(self, msg, *args, **kwargs): - yield LoggingLoggerClass.exception(self, msg, *args, **kwargs) + LoggingLoggerClass.exception(self, msg, *args, **kwargs) def findCaller(self, *args, **kwargs): # NOQA: N802 f = logging.currentframe().f_back