_thread Vs uasyncio
Posted: Sat Jan 22, 2022 11:16 pm
What do you think of _thread Vs uasyncio in terms of the user experience? "Why do you ask?" I hear you say
I got sick of waiting around for urequests to give up on bad connections so I tried timing it out by running it as a thread. Instead of
I did
This worked & the only mod I had to make to _request was to make response a global instead of returning it as previously. Emboldened by this success, I wondered if I might try my luck with uasyncio? Big mistake. First problem, all the online tutorials for uasyncio where way more cerebral than the thread examples. Second, I can't get it to work
I tried moving the class definitions for text, etc inside the asyncio task with the rest of _request but it didn't help. Not only that but the print("_request is running") statement I put at the front of the task never executes so I doubt the _request task has even started. Any thoughts on where I'm going wrong?
I got sick of waiting around for urequests to give up on bad connections so I tried timing it out by running it as a thread. Instead of
Code: Select all
_request("GET", url)
Code: Select all
def _timeout(method, url):
response=0; import _thread; _thread.start_new_thread(_request, (method, url))
for i in range(5): # 5s timeout for dns+srvr
if response: return response
time.sleep(1)
_timeout("GET", url)
Code: Select all
def _timeout(method, url):
response=0; asyncio.create_task(_request(method, url)); await asyncio.sleep(0)
for i in range(5): # 5s timeout for dns+srvr
if response: return response
time.sleep(1)
_timeout("GET", url)
>>AttributeError: generator object has no attribute text