[Python] Getting twisted.internet.error.Reactor Not Restartable when using Kite WebSocket...

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    1.I'm using the Zerodha Kite Connect API inside an AWS Lambda function.

    On the first invocation, the WebSocket works fine, but on subsequent invocations, I get the following error:

    twisted.internet.error. Reactor Not Restartable

    I suspect it has something to do with Twisted's reactor being restarted in a reused container. How can I fix or work around this issue within the Lambda environment?

    1. Beginner-friendly Style

    I'm trying to stream live market data from Zerodha's Kite WebSocket inside an AWS Lambda function. It works fine once, but when I call it again, I get an error saying:

    twisted.internet.error. ReactorNot

    Restartable

    Why does this happen and how can I make my code work for multiple Lambda invocations?

    1. Short and Concise (Forum style)

    Why does KiteTicker.connect() in AWS Lambda throw ReactorNotRestartable on second call? How do I reuse or restart Twisted reactor properly in Lambda?

    1. Debugging-focused

    I'm running Twisted-based Kite WebSocket code in AWS Lambda.

    After the first cold-start, subsequent invocations fail with:

    twisted.internet.error.Reactor Not Restartable

    How can I persist the reactor or restructure my Lambda to avoid this?

    1. Descriptive with Context (for GitHub issues or support forums)

    While using the Kite Connect API (which uses Twisted under the hood) in AWS Lambda, I get a ReactorNotRestartable error after the first invocation. I believe this is due to Lambda reusing the Python process and Twisted not allowing the reactor to be restarted.

    What's the best practice to keep the WebSocket client working reliably across multiple Lambda invocations?

    Continue reading...

Compartilhe esta Página