Skip to content

Commit

Permalink
Run synchronous code asynchronously (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored Sep 30, 2020
1 parent c732b16 commit 525f386
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apprise/py3compat/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 525f386

Please sign in to comment.