kivy-school / kivy-reloader

Hot reload your Kivy app on multiple phones and computer in real-time.
MIT License
18 stars 3 forks source link

Winfix #24

Closed AccelQuasarDragon closed 4 months ago

AccelQuasarDragon commented 4 months ago

fix on windows for kivy-reloader

fixed kivy reloder on windows
issues were:
original issue: when you save and force a reload on windows, keyboardinterrupt was not being caught by new spawned child processes

this is because windows Process is not the same as os.spawnv on linux. (children do not listen to parent's KeyboardInterrupt when parent has exited before child)

the fix is to keep the host open but doing nothing and only "listening" for keyboardinterrupt so it will be send to a future child process.

the fix is to set some argv that is the host Python  pid for 2 things:

#1: intermediate children will exit if they know their argv has the hostPID and they will be replaced with another reloaded child process

#2: the final child that is closed with the "X" button on windows has an on_request_close bound to it that tasks windows to taskkill the original host python. Kinda chicken and egg? but it works on my machine....

#3: the final child will also respond to KeyboardInterrupt because parent is still active.

other issues were:

- FIXED: new windows being created and not destroyed when reloading

- FIXED: when pressing X on the final child window, the original host python would not exit and would be guaranteed leaked memory.
AccelQuasarDragon commented 4 months ago

note, this is NOT chicken and egg because there are 2 scenarios:

keyboardinterrupt > means that you need to find a way to cancel the final child process. from there you keep the host process alive

close the window > from there, the host python does not receive any close command, so the final child must close it using PID