2018-12-15 21:30:09 +01:00
|
|
|
import asyncio
|
2019-01-21 21:55:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
def force_asyncioreactor_install():
|
|
|
|
import sys
|
|
|
|
from twisted.internet import asyncioreactor
|
|
|
|
if 'twisted.internet.reactor' not in sys.modules:
|
|
|
|
asyncioreactor.install()
|
|
|
|
else:
|
|
|
|
from twisted.internet import reactor
|
|
|
|
if not isinstance(reactor, asyncioreactor.AsyncioSelectorReactor) and getattr(sys, 'frozen', False):
|
|
|
|
# pyinstaller hooks install the default reactor before
|
|
|
|
# any of our code runs, see kivy for similar problem:
|
|
|
|
# https://github.com/kivy/kivy/issues/4182
|
|
|
|
del sys.modules['twisted.internet.reactor']
|
|
|
|
asyncioreactor.install()
|
2018-12-15 21:30:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
def d2f(deferred):
|
|
|
|
return deferred.asFuture(asyncio.get_event_loop())
|
|
|
|
|
|
|
|
|
|
|
|
def f2d(future):
|
2019-01-21 21:55:50 +01:00
|
|
|
from twisted.internet import defer
|
2018-12-15 21:30:09 +01:00
|
|
|
return defer.Deferred.fromFuture(asyncio.ensure_future(future))
|