Skip to content

RuntimeError: There is no current event loop in thread 'MainThread' #1099

@0xtflow

Description

@0xtflow

Describe the bug
When running a simple Cryptofeed script with FeedHandler().run(), I get a RuntimeError: There is no current event loop in thread 'MainThread'. The error occurs immediately when trying to start the feed handler.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Python script with the following code:
from cryptofeed.exchanges import Binance
from cryptofeed.defines import CANDLES
from cryptofeed import FeedHandler

async def candle_callback(c, receipt_timestamp):
    print(f"Candle received at {receipt_timestamp}: {c}")

f = FeedHandler()
f.add_feed(
    Binance(
        symbols=["BTC-USDT"],
        channels=[CANDLES],
        callbacks={CANDLES: candle_callback},
    )
)
f.run()
  1. Run the script
  2. See the error:
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    f.run()
  File "site-packages/cryptofeed/feedhandler.py", line 135, in run
    loop = asyncio.get_event_loop()
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/uvloop/__init__.py", line 206, in get_event_loop
    raise RuntimeError(
RuntimeError: There is no current event loop in thread 'MainThread'.

Expected behavior
The feed handler should start successfully and begin receiving candle data from Binance without event loop errors.

Operating System:

  • Ubuntu 25.10

Cryptofeed Version

  • Version: 2.4.1
  • Installation method: PyPI

Python

  • Version: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions