PYTHONWarningRuntime ErrorMay 1, 2026

Runtime Error

RuntimeError: Cannot schedule new futures after shutdown

What This Error Means

This error occurs when you're attempting to use asyncio (a library for concurrent programming in Python) to schedule new tasks after the event loop has been shut down.

Why It Happens

It usually happens when a function scheduled in an asynchronous context is invoked after the event loop has been stopped, or when you're trying to schedule a new task in an already closed loop. This can be due to a misuse of asyncio's context or a wrong usage of the event loop's shutdown.

How to Fix It

  1. 1To prevent this error, ensure that you're not scheduling new tasks after the event loop has been shut down. You can do this by checking the status of the event loop before attempting to schedule a new task. Here's a practical fix:
  2. 2// Before (broken code)
  3. 3import asyncio
  4. 4async def my_task():
  5. 5 await asyncio.sleep(1)
  6. 6// After (fixed code)
  7. 7import asyncio
  8. 8async def my_task():
  9. 9 if not asyncio.get_event_loop().is_closed():
  10. 10 await asyncio.sleep(1)

Example Code Solution

❌ Before (problematic code)
Python
def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(my_task())
    loop.close()
    loop.run_until_complete(my_task())
✅ After (fixed code)
Python
def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(my_task())
    loop.close()

Fix for RuntimeError: Cannot schedule new futures after shutdown

Related PYTHON Errors

Related PYTHON Blog Articles

Have a different error? Get an instant explanation.

Explain Another Error