pythonmultithreadingasynchronousstripe-payments

Running Stripe Asynchronously


The following code takes few second to run:

payments = stripe.PaymentIntent.list(limit=10000)

How I can make the above code run asynchronously?

I tried await payments = stripe.PaymentIntent.list(limit=10000) but I received the error SyntaxError: cannot assign to await expression


Solution

  • import time
    import asyncio       
    import threading
    
    
    async def myfunction():
    
        await asyncio.sleep(10) #  sleep for 10 seconds
    
        payments = stripe.PaymentIntent.list(limit=10000)
    
    
    server=threading.Thread(target=asyncio.run, args=(myfunction(),))
    
    server.start()