After running my virtual machine with this command in Python:
os.system('emulator -avd Galaxy_Note9_API_27 -writable-system -no-snapshot-update-time')
I try to wait with another command (command below) until the device is fully loaded
os.system("adb -s emulator-5554 wait-for-device shell 'while [[ -z $(getprop dev.bootcomplete) ]] ; do sleep 1; done'")
But my problem with the above code is that it is a while loop but I want it to be in such a way that if after 120 seconds of waiting for the device to load it will return an error to me because I encounter this problem a lot that my device would crash when running and I would get stuck in an infinite loop
It's not clear why you are using
pythonto invokeadbcommand, however if there's a reason, you can usesubprocess, for many other reasons but because it supports timeout too, instead ofos.system: