Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4475

MicroPython • urequests and _thread: issue

$
0
0
Dear users,

currently, I'm developing a program that uses both urequests and _thread on my Pico W. Everything works fine until I uncomment the line _thread.start_new_thread(blinken, ()) which should start a function on the other core that does nothing but printing "Hello" periodically.

Code:

import urequests, network, time, _threaddef blinken():    while True:        print("Hello")        time.sleep_ms(10 * 1000)wlan = network.WLAN(network.STA_IF)wlan.active(True)wlan.connect('xxx', 'yyy')#_thread.start_new_thread(blinken, ())while True:    print("Rstart")    request = urequests.get('http://example.com/test.php', auth=('xxx' , 'yyy'))    content = request.text    time.sleep_ms(1)    print("Rend")    request.close()    time.sleep_ms(30 * 1000)
When I uncomment the mentioned line and restart the program the following error occurs (already in the first iteration of the while-True-Loop that contains the request):

Code:

Traceback (most recent call last):  File "<stdin>", line 16, in <module>  File "requests/__init__.py", line 201, in get  File "requests/__init__.py", line 94, in requestOSError: [Errno 103] ECONNABORTED
I should mention that the urequest.get() needs about 10 seconds to get its data from the server (that's normal because the server needs some time to assemble this data; the received size of the received data doesn't cause any memory overflow).
I already did some research and tried using the timeout option in get, but that didn't work. The network connection is stable. I couldn't find out any reasons for that behavior. That's why I would be glad if you could assist me solving this issue.

Yours sincerely,
flori8029

Statistics: Posted by flori8029 — Mon Jan 20, 2025 12:36 pm — Replies 2 — Views 48



Viewing all articles
Browse latest Browse all 4475

Trending Articles