Force socket closure?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Force socket closure?

Post by warren » Sun Sep 11, 2016 7:21 pm

I expect that the answer to this is "No" - but people here have a lot more python experience than I, so I will ask...

I have a micropython script running on an ESP8266 board. It makes a regular call to a cgi script on a remote server. It is using the socket code suggested in the docs.

99% of the time it works flawlessly. This remains true even if I make it do socket operations every two seconds - just works well.

"Now and then" it 'hangs'. It's as if it is still waiting for a network operation to finish. If at that point I press CTRL-C, it breaks out of the socket call script and back into the main loop. Further calls from that loop to make new sockets continue to work perfectly...

QUESTION: I could easily set up a timer to monitor the time that the socket routine has been invoked for a particular connection - and force a close of that socket if it passes a threshold.

But what could I do to force the close of the socket from 'outside' the code that instantiated it?


Obviously, the socket functions in Micropython are a subset of the main Python libraries - so I suspect there is no option for some form of non-blocking behaviour etc...

Any ideas?

Thanks

P.S. I think that I have ruled out any board-specific issues, I have had two different ESP boards running the identical script (but calling different cgi-scripts) and usually they both 'hang' at around the same time. The two boards are very different from each other... (one a Sonof and one a generic bare metal).

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Force socket closure?

Post by deshipu » Sun Sep 11, 2016 7:52 pm

I'm not sure if it helps, but you can set a timeout on the socket itself.

warren
Posts: 74
Joined: Tue Jul 12, 2016 5:47 pm

Re: Force socket closure?

Post by warren » Sun Sep 11, 2016 9:20 pm

deshipu wrote:I'm not sure if it helps, but you can set a timeout on the socket itself.
Thank you - it is indeed exactly what I need...I cant understand how I missed this in the documentation...

Post Reply