shazamio / ShazamIO

🎵 Is a free asynchronous library from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp.
MIT License
449 stars 64 forks source link

This event loop is already running #72

Closed xts-bit closed 4 months ago

xts-bit commented 10 months ago

When i try to run this code on a google collab it gives error RuntimeError: This event loop is already running

What i did: !pip install shazamio

my code:

import asyncio
from shazamio import Shazam

async def main():
  shazam = Shazam()
  tracks = await shazam.search_track(query='Lil', limit=5)
  print(tracks)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Full Error:

RuntimeError                              Traceback (most recent call last)
[<ipython-input-3-9a17980d49a4>](https://localhost:8080/#) in <cell line: 11>()
      9 
     10 loop = asyncio.get_event_loop()
---> 11 loop.run_until_complete(main())

1 frames
[/usr/lib/python3.10/asyncio/base_events.py](https://localhost:8080/#) in _check_running(self)
    582     def _check_running(self):
    583         if self.is_running():
--> 584             raise RuntimeError('This event loop is already running')
    585         if events._get_running_loop() is not None:
    586             raise RuntimeError(

RuntimeError: This event loop is already running
dotX12 commented 4 months ago

Better late than never, but it happened thanks to pyo3 and RUST. https://github.com/dotX12/shazamio-core

Fixed in 0.5.0. See comment: https://github.com/shazamio/ShazamIO/issues/76#issuecomment-1961610344