[x] I have tested my changes against the dev branch (the latest developmental version), and this pull request is targeting that branch as a base
[x] I have tested my changes on Python 3.8.10 on windows and 3.10.12 on linux
[x] I have ensured my code is formatted using Black
Description
This PR expands the restart command to enable full restarts that will reload source files. Additionally this cleans up some logic involved with soft restarts and normal shutdowns to reduce errors.
The restart command now takes an optional argument restart full to trigger a full respawn of the the process. By default restart soft is implied and will only re-initialize the bot from the currently loaded process.
On Linux, Mac, and other Unix-style OS, the process will be replaced using execlp to keep the current Process ID.
On Windows, the original process will be closed, and a new one will be spawned in a new console window. Subsequent console windows will automatically close when the bot closes, but the original window will always remain.
Additionally, this PR adds three sub-commands to restart which will attempt to upgrade the bot or its dependencies or both, and restart. These are documented in the commands help text / doc string.
Exhaustive testing has not been done against all the bots commands, in regards to shutdown cleanup changes. So there may still be errors generated from pending tasks that manage to survive a soft restart.
Things of note
The use of subprocess.Popen is not a blocking call, as implied in #1494 and using subprocess.CREATE_NEW_CONSOLE flag enables us to break away from the parent process tree, preventing long chains of processes.
The use of os.execlp on linux/mac may not flush pending data in file or IO buffers. These need to be flushed and closed before execlp call is made.
Tests done thus far
Restart the bot 15 times using each restart method and record memory usage:
Windows restart soft used about 27 MiB extra memory in total, according to Task Manager
Windows restart full used about 8 MiB extra memory in total, by Task Manager
Linux restart soft used used about 13 MiB extra memory in total, according to SystemD service.
Linux restart full used no extra memory according to Top.
Restart the bot and inspect process tree behavior:
Windows restart soft results in no process tree changes.
Windows restart full results in new process tree, old process is closed except for originating console session.
This is because run.bat keeps the console open! (and it should probably stay that way, imo)
Linux restart soft results in no process tree changes.
Linux restart full results in no process tree change, the old PID is kept by the reloaded program.
dev
branch (the latest developmental version), and this pull request is targeting that branch as a baseDescription
This PR expands the restart command to enable full restarts that will reload source files. Additionally this cleans up some logic involved with soft restarts and normal shutdowns to reduce errors.
The restart command now takes an optional argument
restart full
to trigger a full respawn of the the process. By defaultrestart soft
is implied and will only re-initialize the bot from the currently loaded process.On Linux, Mac, and other Unix-style OS, the process will be replaced using
execlp
to keep the current Process ID. On Windows, the original process will be closed, and a new one will be spawned in a new console window. Subsequent console windows will automatically close when the bot closes, but the original window will always remain.Additionally, this PR adds three sub-commands to
restart
which will attempt to upgrade the bot or its dependencies or both, and restart. These are documented in the commands help text / doc string.Exhaustive testing has not been done against all the bots commands, in regards to shutdown cleanup changes. So there may still be errors generated from pending tasks that manage to survive a soft restart.
Things of note
The use of
subprocess.Popen
is not a blocking call, as implied in #1494 and usingsubprocess.CREATE_NEW_CONSOLE
flag enables us to break away from the parent process tree, preventing long chains of processes.The use of
os.execlp
on linux/mac may not flush pending data in file or IO buffers. These need to be flushed and closed before execlp call is made.Tests done thus far
Restart the bot 15 times using each restart method and record memory usage:
restart soft
used about 27 MiB extra memory in total, according to Task Managerrestart full
used about 8 MiB extra memory in total, by Task Managerrestart soft
used used about 13 MiB extra memory in total, according to SystemD service.restart full
used no extra memory according to Top.Restart the bot and inspect process tree behavior:
restart soft
results in no process tree changes.restart full
results in new process tree, old process is closed except for originating console session.restart soft
results in no process tree changes.restart full
results in no process tree change, the old PID is kept by the reloaded program.