Reputation: 65
I'm making a Discord client (in old discord.py). Discord requires regular communications or else it will close the connection and subsequently make my program crash. My client requires user input (via input command) for the message which prevents the request from being made and making it crash.
Is there a way to ask for user input and let other code run in the background?
Upvotes: 0
Views: 102
Reputation: 846
Use threading:
from _thread import start_new_thread as thread
def othercode(): # Code which will execute during input
print("bloop")
def inputcode(): # Code which will recieve input
global thing
thing = input("input: ")
thread(othercode) # Start a thread
inputcode() # STart the input script on the main thread
Upvotes: 1