pyjuque icon indicating copy to clipboard operation
pyjuque copied to clipboard

Bot does not stop with Ctrl+C?

Open Jsalaz1989 opened this issue 2 years ago • 7 comments

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: image

Am I misunderstanding something?

Thanks

Jsalaz1989 avatar Jun 06 '22 10:06 Jsalaz1989

tudor pls

Jsalaz1989 avatar Jun 15 '22 17:06 Jsalaz1989

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

tudorelu avatar Jun 16 '22 00:06 tudorelu

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.

image

Jsalaz1989 avatar Jun 16 '22 18:06 Jsalaz1989

Maybe try these SO answers: https://stackoverflow.com/a/5114409/4468246 https://stackoverflow.com/a/47495035/4468246

tudorelu avatar Jul 15 '22 02:07 tudorelu

I think it's more of an issue with your logging of "Executed the bot loop. Now waiting...". Look at this:

image

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.

Jsalaz1989 avatar Jul 15 '22 14:07 Jsalaz1989

Oh that makes sense, it's probably to do with yaspin (the spinner/logger)

tudorelu avatar Jul 16 '22 09:07 tudorelu

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...":

image

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?

Jsalaz1989 avatar Jul 20 '22 13:07 Jsalaz1989