Create a new event loop in the Pushbullet backend

This commit is contained in:
Fabio Manganiello 2018-12-24 11:37:18 +01:00
parent 6a48a53c0d
commit b911d46315
2 changed files with 7 additions and 3 deletions

View file

@ -5,7 +5,7 @@ import time
import websockets
from platypush.config import Config
from platypush.context import get_or_create_event_loop
from platypush.context import create_event_loop
from platypush.message import Message
from platypush.message.event.pushbullet import PushbulletEvent
@ -98,7 +98,6 @@ class PushbulletBackend(Backend):
return is_duplicate
def on_push(self, ws, data):
print('***** {}'.format(data))
try:
# Parse the push
try:
@ -152,8 +151,8 @@ class PushbulletBackend(Backend):
self.on_push(self.ws, push)
self.close()
loop = get_or_create_event_loop()
loop = create_event_loop()
loop.run_until_complete(pushbullet_client())
loop.run_forever()

View file

@ -114,6 +114,11 @@ def register_plugin(name, plugin, **kwargs):
""" Registers a plugin instance by name """
global plugins
def create_event_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
return loop
def get_or_create_event_loop():
try:
loop = asyncio.get_event_loop()