#π Using VS code and trying to interrupt the terminal with "ctrl + c" doesn't seem to work (unrelated
154 messages Β· Page 1 of 1 (latest)
@sharp dove
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Can you show a screenshot of your VSCode and terminal?
oh ok. If you click in the terminal and hit CTRL + C, what happens?
oh hang on, you're using the debug play button instead of typing a command
nothing at all happens
What happens if you stop the run, then type py bot.py in your terminal and hit enter, then CTRL + C?
@sharp dove
same thing
no output at all in any way shape or form no matter what i click in the terminal
You'll probably need to check your keybinding settings
CTRL + SHIFT + P to open up your Command Pallete
Type "Keyboard Shortcuts"
press enter
what libraries u got imported
import logging
import os
import platform
import random
import sys
import aiosqlite
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Context
from dotenv import load_dotenv
from database import DatabaseManager```
Hey @sharp dove!
Add a py after the three backticks.
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
Can you also share what extensions you've installed on VSCode @sharp dove ?
ok thats fine
this would just kill the whole terminal and not interrupt it, no?
hold on
this feels like something is catching KeyboardInterrupt for some reason 
and thats why we need to see your code
it's not vscode's fault
the KeyboardInterrupt is definitely being caught and ignored by your code, you need to share your code so we can tell you where this is happening
why
no please just send the code as text
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
yes
most likely, the issue is around wherever you call bot.run()
if its over 100 lines long send it using paste link please
where do you run the bot
if it's really just that, then the problem doesn't appear to be here
I wonder what is in database
also just to be clear, you are using discord.py and not some derivative library right
yes
import aiosqlite
import discord
from discord.ext import commands, tasks
from discord.ext.commands import Context
from dotenv import load_dotenv
Hey @sharp dove!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
these r the ones
I don't see anything in the code that would override a KeyboardInterrupt event
it would also work if something was catching BaseException for some reason
Can I get all of the files @sharp dove ? I'd like to try and run this myself and see if I get the same issue
sure
Can you please share the database
I'm suspecting that you probably have some threads that aren't closing
yea i havent even looked at it, don't have a db viewer either
no
i mean when you run import database
what's that
because discord.py drops KeyboardInterrupts and assumes that asyncio will deal with it
discord/client.py lines 905 to 911
try:
asyncio.run(runner())
except KeyboardInterrupt:
# nothing to do here
# `βasyncio.run`β handles the loop cleanup
# and `βself.start`β closes all sockets and the HTTPClient instance.
return```
but asyncio won't deal with threads
from database import DatabaseManager
this is
all in bot.py
idk where it imports it otherwise
is there not a database.py file?
do u have a database.py
Is there like a Github repo that have all of these files so I can clone and test it out properly?
yeah
Looks like that there's a bunch of files here
was just gonna zip it
Can you share the repo?
had to find it sorry
Thanks
you want the code of each file?
or just here
i added a bunch
ah it did not let me send
Tried it. Yeah something is blocking the CTRL + C here
But I think the reason for this is so that it doesn't accidentally get closed while running it
it seems to be intended to be used with docker ? 
so instead of ctrl+c ig it wants u to nuke container running bot instead ?
but whats blocking CTRL + C tho?
Β―_(γ)_/Β―
Same
I don't see anywhere on how this bot blocks CTRL + C
Not entirely
my bet is the console_handler for logging
βοΈ potential reason too
that feels like a prime suspect
They could
if you add
bot = DiscordBot()
bot.run("token")
# add this
import asyncio
asyncio.run(bot.database.connection.close())
then the bot closes correctly
the correct way to do this is to make DatabaseManager a context manager
yup
just for the sake of teaching something, you can figure this out by running python -i bot.py
so that you get an interactive terminal after the main file reaches its endd
and from there you can inspect the list of running threads
>>> for t in threading.enumerate():
... print(f"Thread: {t.name}, Daemon: {t.daemon}, Alive: {t.is_alive()}")
...
Thread: MainThread, Daemon: False, Alive: True
Thread: Thread-2, Daemon: False, Alive: True
lo and behold, theres a second thread still alive
there should only be one
Nice detective work @bleak wasp
if you look at the database connection
>>> bot.database.connection
<Connection(Thread-2, started 14876)>
then you'll see that this connection is also using "Thread-2"
good to know -i exists
oh yeah
quite useful indeed
man how have i been doing python for like 7y and i still dont know all the useful tools in a default installation
there's always more
well holy shit, me getting stupidly pissed i gotta click 3 extra buttons thinking it's vs code
_^
also ive been at it for 10 years so clearly the insight all comes in the next 3
thank you man, really appreciated
np
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
