Unable to Call the Django Function

def ravi(request):
    if request.method = "POST":
        entered_index = request.POST['index']
        socket_opened = False
        def event_handler_quote_update(message):
            print(f"quote update {message}")

        def open_callback():
            global socket_opened
            socket_opened = True

        alice.start_websocket(subscribe_callback=event_handler_quote_update,
                              socket_open_callback=open_callback,
                              run_in_background=True)
        while(socket_opened==False):
            pass
        alice.subscribe(alice.get_instrument_by_symbol('NSE','ONGC'),LiveFeedType.MARKET_DATA)
    form = trades()
    return render(request, "blog/box_breakout.html",{'form': form}) 

"When I call the function, the browser keeps on loading. It neither works nor giving me the error" .

Yoyr function stucks in the while loop you need to give a statement for socket_opened==False to break the loop

Back to Top