[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
This commit is contained in:
Chase Sterling 2022-02-02 00:21:54 -05:00 committed by Calum Lind
parent b76f2c0f20
commit 2fb41341c9
No known key found for this signature in database
GPG Key ID: 90597A687B836BA3
3 changed files with 20 additions and 27 deletions

View File

@ -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

View File

@ -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)

View File

@ -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