mirror of https://github.com/caronc/apprise
Run synchronous code asynchronously (#304)
parent
c732b16d43
commit
525f386959
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
from functools import partial
|
||||||
from ..URLBase import URLBase
|
from ..URLBase import URLBase
|
||||||
from ..logger import logger
|
from ..logger import logger
|
||||||
|
|
||||||
|
@ -101,7 +103,12 @@ class AsyncNotifyBase(URLBase):
|
||||||
Async Notification Wrapper
|
Async Notification Wrapper
|
||||||
"""
|
"""
|
||||||
try:
|
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:
|
except TypeError:
|
||||||
# These our our internally thrown notifications
|
# These our our internally thrown notifications
|
||||||
|
|
Loading…
Reference in New Issue