Raspberry Pi 4. So I have a python script (run at startup) with a GUI where it is possible to select a wifi network form a list and enter its password; such infos are saved to a file which will later (at startup) substitute the wpa_supplicant file. The system is then reboot (my python file does it), but when it is back on (and the entire wpa_supplicant gets updated) the Wi-Fi is not connected. It takes another reboot to get to Wi-Fi to successfully connect and work. From various sources (stackoverflow and stackexchange) I was able to obtain and successfully use (kinda) the code below:
subprocess.check_output('sudo chmod 777 /etc/wpa_supplicant/wpa_supplicant.conf', shell= True)
(The line above is maybe necessary because my Pi is in read-only)
shutil.copyfile('/media/pi/ALLDATA/wpa_supplicant.conf', '/etc/wpa_supplicant/wpa_supplicant.conf')
(copy the file from a USB stick to the wpa_supplicant location)
os.system("sudo service networking restart")
(restart networking)
So the question is: why do I need a futher reboot (a total of two) after changing wpa_supplicant for the Wi-Fi to work?