I've been building a twitch chatbot for Python that has some custom games that I'm adding to have something for viewers to use while they watch my stream. My current goal is to make a dice duel game (2 player game where whoever gets the highest number wins the sum of the bets made). In order to play, I want both players to accept the match before allowing it to continue, but I also want to implement a match timer so that if the other user doesn't accept the match before a timer expires, it will cancel the game. I want to make a new thread for each game and scan to see if the game has expired or not, but need them to run in parallel to the rest of the chatbot, or else I can only have 1 game at a time, and the rest of the bot will grind to a halt when it happens.
What I've already tried is this using the multithreading module included with Python by making two processes, and starting them. I've also tried using the threading modules, and it provides the same result. Here is the multithreading code I wrote to attempt to make it work.
processes = []
# Tick has a basic print statement, and a sleep statement for testing.
# Tried without the sleep, and used a for loop to print "test" 100 times as well to see if the sleep was causing the issue
tickprocess = multiprocessing.Process(target=tick())
processes.append(tickprocess)
# Main initializes settings and starts the chatbot
chatbotprocess = multiprocessing.Process(target=main())
processes.append(chatbotprocess)
for item in processes:
item.start()
What this does is it will start the tick process, but it waits for it to complete before starting the chatbot process which is the opposite of what I want to do since I could just call the tick function and then the main function to get the same result. Am I misunderstanding what these modules are for? The end goal is to start a game thread when the dice command is received, but still allow the bot to work synchronously and handle other commands and games (all games to this point run instantly or close enough to instantly that conflicts are not an issue).