From 525f3869597be64ea2e6e5df95c6779dff31b431 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 29 Sep 2020 21:27:19 -0400 Subject: [PATCH] Run synchronous code asynchronously (#304) --- apprise/py3compat/asyncio.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apprise/py3compat/asyncio.py b/apprise/py3compat/asyncio.py index 626b9bbb5..a2dd68af0 100644 --- a/apprise/py3compat/asyncio.py +++ b/apprise/py3compat/asyncio.py @@ -25,6 +25,8 @@ import sys import asyncio +from concurrent.futures import ThreadPoolExecutor +from functools import partial from ..URLBase import URLBase from ..logger import logger @@ -101,7 +103,12 @@ async def async_notify(self, *args, **kwargs): # noqa: E999 Async Notification Wrapper """ try: - return self.notify(*args, **kwargs) + loop = asyncio.get_event_loop() + with ThreadPoolExecutor() as executor: + return await loop.run_in_executor( + executor, + partial(self.notify, *args, **kwargs), + ) except TypeError: # These our our internally thrown notifications