olucurious / PyFCM

Python client for FCM - Firebase Cloud Messaging (Android, iOS and Web)
http://olucurious.github.io/PyFCM/
MIT License
802 stars 204 forks source link

Error: Cannot run the event loop while another loop is running when using async_notify_multiple_devices #348

Open tranvannhat opened 1 month ago

tranvannhat commented 1 month ago

fastapi = "^0.111.0" pyfcm = "^2.0.4" I using async_notify_multiple_devices and get error: Cannot run the event loop while another loop is running

vmtniichov commented 1 month ago
from pyfcm.async_fcm import fetch_tasks
from pyfcm.baseapi import BaseAPI

class FCMNotification(BaseAPI):

    async def send_async_request(self, params_list, timeout=5):
        payloads = [self.parse_payload(**params) for params in params_list]
        responses = await fetch_tasks(
            end_point=self.FCM_END_POINT,
            headers=self.request_headers(),
            payloads=payloads,
            timeout=timeout,
        )

        return responses

Create a new FCM class inherit from the BaseAPI and replace async_notify_multiple_devices usages with send_async_request will resolve your issue