Run synchronous code asynchronously (#304)

pull/307/head
Raman Gupta 2020-09-29 21:27:19 -04:00 committed by GitHub
parent c732b16d43
commit 525f386959
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

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