如何杀死使用输入的线程?
我正在尝试使用插座和线程制作在线游戏。这是一款竞争激烈的游戏游戏,其中最快的游戏能够完成胜利。我希望,当一位球员赢得/跑出生命时,另一个球员被踢出了比赛,并被告知他们赢了/输了。但是,我遇到了一个问题。
1:如果我使用“线程”,则无法关闭线程(由于程序需要读取用户输入,因此我需要使用input()函数,这意味着播放器的线程直到他们的线程才能终止插入角色)。
2:如果我使用“多处理”(具有终止()函数),则无法使用input()(多处理不允许)。
我陷入僵局,我该怎么办?
PD:这是我有史以来的第一个Stackoverflow帖子,请告诉我是否在写帖子时犯了一个错误!
I am trying to make an online game using socket and threading. It is a competitive hangman game, where the fastest one to complete the word wins. I want that, when one of the players wins/runs out of lives, the other player gets kicked out of its game and is told that they have won/lost. However, I have run into a problem.
1: If I use "threading", there is no way to close the thread (since the program needs to read user input, I need to use the input() function, which means that the player's thread can't be terminated until they insert a character).
2: If I use "multiprocessing" (which has a terminate() function), I can't use input() (multiprocessing doesn't allow it).
I am in a stalemate, what should I do?
P.D: This is my first stackoverflow post ever, please tell me if I made a mistake at writing the post!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我明白了,这是一个丑陋而复杂的解决方案,但它起作用。
我创建了一个模拟“输入”命令的程序,而不是输入命令本身(因此它不会停止进程)。
这里是:
Ok, I got it, it is an ugly and complicated solution, but it works.
I created a program that emulates the "input" command, without being the input command itself (so it doesn't stop the processes).
Here it is: