Open dgw opened 9 months ago
I've run into intermittent problems with restarting using the typical sopel restart -c configname
spelling, too. Hard to troubleshoot as sometimes it works fine, sometimes not. Could be related to restarting the same instance multiple times… Log/traceback snippet follows, but it might deserve its own issue; not sure yet.
# Main shell:
dgw@borealis:~$ sopel restart -c yuzu
Asking Sopel to restart
dgw@borealis:~$
# tmux session where Sopel is running:
[... shutdown stuff ...]
[2023-11-22 08:14:55,705] sopel.bot DEBUG - Calling sopel.coretasks.shutdown
Traceback (most recent call last):
File "/home/dgw/.local/bin/sopel", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/dgw/sopel/sopel/cli/run.py", line 467, in main
return command(opts)
^^^^^^^^^^^^^
File "/home/dgw/sopel/sopel/cli/run.py", line 328, in command_start
os.execv(sys.executable, ['python'] + sys.argv)
FileNotFoundError: [Errno 2] No such file or directory
dgw@borealis:~/sopel$
Can confirm, if I start a Sopel instance (with the normal sopel -c configname
command line) and later restart it once it's fine, then the restart fails with the FileNotFoundError
traceback shown above on the second restart command.
Tested on a bot with basically no plugins (just version
and one of my custom ones), less than a minute after startup, and with just a few seconds between the two restart commands. Unlikely that plugins are interfering with this, and it's also seemingly not related to a long-running bot either (which should make it easier to debug further when we're ready).
It's "good practice" to use
python3 -m
in many cases, and Sopel works just fine if started usingpython3 -m sopel.cli.run
. Yet, trying to restart it fails usingpython3 -m sopel.cli.run restart
(orsopel restart
, if thesopel
script comes from the samepython3
) fails:Something about the restart implementation here is allowing the environment or invocation to change just enough that the new instance can't run properly:
https://github.com/sopel-irc/sopel/blob/03dd79b232e084eb997c7ac9a958995c6b8501a1/sopel/cli/run.py#L326-L328
I admit that I haven't troubleshooted (troubleshot?) this beyond testing the behavior and tracking down the responsible code, but it's interesting to find an unanswered comment on Stack Overflow (Ctrl+F for
python -m
if the anchor link doesn't work) about this exact situation on a question about having Python scripts restart themselves. I guesssys.execv()
, seemingly the accepted solution for having Python programs restart themselves, just doesn't handle this case?This is explicitly not a blocker for 8.0, btw. I just want to document it before I forget.