Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

How to pass arguments to a callback function in Python?

$
0
0

I want to make my code Async for HTTP calls, since the whole program stops while the call is being made.

I took a look at grequests and couldn't figure it out, same for asyncio

this is the current sync version of the code:

myvar1 = class_object()response = requests.get(myvar1.url)if response.status_code == 200:    myvar1.accept()

I would like to do the following instead:

def myfunction:    request.get(myvar1.url,callbackfunction(response,myvar1))    return Nonedef callbackfunction(response,myvar1):    if response.status_code == 200:        myvar1.accept()

I can successfully pass a callback function to the request, the question is how to pass arguments to that callback.

Basically, the goal is to execute a method of the passed argument of the callback function.


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>