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

View File

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