Python not getting IP if cable connected after script has started

后端 未结 3 1671
醉酒成梦
醉酒成梦 2021-01-16 14:51

I hope this doesn\'t cross into superuser territory.

So I have an embedded linux, where system processes are naturally quite stripped. I\'m not quite sure which syst

3条回答
  •  太阳男子
    2021-01-16 15:27

    Sounds like httplib caches /etc/resolv.conf which is updated after your DHCP client obtains an IP.

    You might consider writing a wrapper script that waits until an IP address is obtained, then calls your python script.

    Alternatively, you could try to, within your python script, not open any socket connections until you have acquired an IP address and /etc/resolv.conf updated.

    Edit

    httplib uses socket.create_connection() which, after some searching, I found does cache /etc/resolv.conf. (Well, it seems that the embedded version of libc is actually doing the caching).

    You could try SugarLabs' solution, although I can't speak to it's effectiveness.

提交回复
热议问题