找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3456|回复: 1

[求助] 多线程,与某个线程交互的问题

1

主题

1

帖子

7

积分

贫民

积分
7
ljm0211 发表于 2015-7-20 15:37:50 | 显示全部楼层 |阅读模式
用以下代码启动多线程,如果已经启动了多个线程,比如4个,现在想要与其中一个线程做用户交互,应该怎么写代码?
class timer(threading.Thread): #The timer class is derived from the class threading.Thread
    def __init__(self, num, interval):
        threading.Thread.__init__(self)
        self.thread_num = num
        self.interval = interval
        self.thread_stop = False
        self.thread_pause = False
        self.count = 0
        self.showtimes = 0

    def run(self): #Overwrite run() method, put what you want the thread do here
        while not self.thread_stop:
                time.sleep(self.interval)
                self.count = self.count + self.thread_num
    def stop(self):
        self.thread_stop = True


回复

使用道具 举报

0

主题

23

帖子

23

积分

贫民

积分
23
关大叔 发表于 2015-8-4 14:28:41 | 显示全部楼层
最直接就是需要交互的内容需要用全局
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表