fix thread stop

This commit is contained in:
xw_y_am@rmbp 2018-04-24 17:56:15 +08:00
parent 6ca3aec978
commit 4e9375eee5
2 changed files with 16 additions and 4 deletions

View File

@ -10,14 +10,22 @@ class Sites:
def __del__(self):
print(self.name, 'stop !')
def stop(self):
self.to_stop = True
def search(self, key_word):
self.to_stop = False
key_word = self.trns_key(key_word)
for url in self.gen_url(key_word):
if self.to_stop:
return
try:
soup = self.fetch_soup(url)
except:
break
for item in self.get_item(soup):
if self.to_stop:
return
if 'link_url' in item:
try:
item['link'] = self.get_link(self.fetch_soup(item['link_url']))

12
ux.py
View File

@ -29,8 +29,9 @@ class Ux(QMainWindow, window.Ui_MainWindow):
self.state.showMessage('Over')
if self.timer.isActive():
self.timer.stop()
while self.th_search.isRunning():
self.th_search.exit()
if self.th_search.isRunning():
self.th_search.stop()
self.th_search.wait()
def on_cb_source_currentIndexChanged(self, index):
if type(index) == type(1):
@ -83,6 +84,9 @@ class SearchThread(QThread):
def run(self):
if not self.key:
return
search = self.site(self.to_append_result)
search.search(self.key)
self.search = self.site(self.to_append_result)
self.search.search(self.key)
self.to_stop_search.emit()
def stop(self):
self.search.stop()