pyjuque
pyjuque copied to clipboard
Bot does not stop with Ctrl+C?
Hello,
I have the typical loop in my file:
def main():
bot_controller = defineBot(bot_config)
while True:
try:
bot_controller.executeBot()
except KeyboardInterrupt:
return
sleep(15)
However, when I hit ctrl+c the terminal appears to react but not actually stop the program:
Am I misunderstanding something?
Thanks
tudor pls
Hey hey, so you see how 'sleep(15)' is outside the scope of 'try'? You want to put it inside, so the KeyboardInterrupt will work while the bot is waiting.
try:
bot_controller.executeBot()
sleep(15)
except KeyboardInterrupt:
return
That's like the first thing I tried. If I bring in the sleep(15)
inside the try
it won't even react to the Ctrl+C. The terminal never stops showing the "Executed the bot loop. Now waiting...". The following screenshot is after trying to send Ctrl+C multiple times to the terminal.
Maybe try these SO answers: https://stackoverflow.com/a/5114409/4468246 https://stackoverflow.com/a/47495035/4468246
I think it's more of an issue with your logging of "Executed the bot loop. Now waiting...". Look at this:
After ctrl+c the first time you can see it prints the "inside except". However, after that, your logging is still spinning with the "Executed the bot loop. Now waiting..." and even if I try ctrl+c again, it doesn´t react in any way.
Oh that makes sense, it's probably to do with yaspin (the spinner/logger)
While you're looking into that, would it also make sense to look into the following?
When the bot places a sell order, it repeatedly prints out "OPEN SELL order on...":
It just keeps filling up the terminal with it. Wouldn´t it be better to just print it once and then if anything new happens, print the new change?