我在使用pyGTK应用程序时遇到了一些问题.我给线程一些时间来完成它的任务,如果有问题我只是继续但是警告用户.但是一旦我继续,这个线程就会停止,直到调用gtk.main_quit.这让我很困惑.
相关代码:
class MTP_Connection(threading.Thread):
def __init__(self, HOME_DIR, username):
self.filename = HOME_DIR + "mtp-dump_" + username
threading.Thread.__init__(self)
def run(self):
#test run
for i in range(1, 10):
time.sleep(1)
print i
Run Code Online (Sandbox Code Playgroud)
..........................
start_time = time.time()
conn = MTP_Connection(self.HOME_DIR, self.username)
conn.start()
progress_bar = ProgressBar(self.tree.get_widget("progressbar"),
update_speed=100, pulse_mode=True)
while conn.isAlive():
while gtk.events_pending():
gtk.main_iteration()
if time.time() - start_time > 5:
self.write_info("problems closing connection.")
break
#after this the program continues normally, but my conn thread stops
Run Code Online (Sandbox Code Playgroud)