Skip to content

Commit d5e7c0b

Browse files
committed
fix thread error
1 parent 691dad0 commit d5e7c0b

File tree

5 files changed

+36
-102
lines changed

5 files changed

+36
-102
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Library
1010
Library/*
1111
Library.zip
1212
*.log
13+
.settings
14+
.project
15+
.pydevproject
1316
call_detail.png
1417
Resources/Data/*
1518
Resources/Images/Avatars/*.jpg

.project

Lines changed: 0 additions & 17 deletions
This file was deleted.

.pydevproject

Lines changed: 0 additions & 8 deletions
This file was deleted.

.settings/org.eclipse.core.resources.prefs

Lines changed: 0 additions & 72 deletions
This file was deleted.

Utils/GitThread.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ def __init__(self, account, password, *args, **kwargs):
4646
super(LoginThread, self).__init__(*args, **kwargs)
4747
self.account = account
4848
self.password = password
49+
50+
@classmethod
51+
def quit(cls):
52+
"""退出线程
53+
:param cls:
54+
"""
55+
if hasattr(cls, '_thread'):
56+
cls._thread.quit()
57+
AppLog.info('login thread quit')
4958

5059
@classmethod
5160
def start(cls, account, password, parent=None):
@@ -54,11 +63,6 @@ def start(cls, account, password, parent=None):
5463
:param account: 账号
5564
:param password: 密码
5665
"""
57-
if hasattr(cls, '_thread'):
58-
cls._thread.quit()
59-
cls._thread.wait(1000)
60-
cls._thread.deleteLater()
61-
AppLog.info('login thread killed')
6266
cls._thread = QThread(parent)
6367
cls._worker = LoginThread(account, password)
6468
cls._worker.moveToThread(cls._thread)
@@ -105,11 +109,13 @@ def run(self):
105109
Signals.loginErrored.emit(QCoreApplication.translate(
106110
'Repository', 'Incorrect account or password'))
107111
AppLog.warn('Incorrect account or password')
112+
LoginThread.quit()
108113
return
109114
if 'login' not in retval:
110115
Signals.loginErrored.emit(QCoreApplication.translate(
111116
'Repository', 'Login failed, Unknown reason'))
112117
AppLog.warn('Login failed, Unknown reason')
118+
LoginThread.quit()
113119
return
114120
# 用户ID
115121
uid = retval.get('id', 0)
@@ -137,6 +143,7 @@ def run(self):
137143
AppLog.exception(e)
138144

139145
AppLog.info('login thread end')
146+
LoginThread.quit()
140147

141148

142149
class ProgressCallback(RemoteCallbacks):
@@ -155,6 +162,15 @@ class CloneThread(QObject):
155162
"""
156163

157164
Url = 'git://github.com/PyQt5/PyQt.git'
165+
166+
@classmethod
167+
def quit(cls):
168+
"""退出线程
169+
:param cls:
170+
"""
171+
if hasattr(cls, '_thread'):
172+
cls._thread.quit()
173+
AppLog.info('clone thread quit')
158174

159175
@classmethod
160176
def start(cls, parent=None):
@@ -263,6 +279,7 @@ def run(self):
263279
AppLog.info('clone thread end')
264280
Signals.progressStoped.emit()
265281
Signals.cloneFinished.emit('')
282+
CloneThread.quit()
266283

267284

268285
class UpgradeThread(QObject):
@@ -274,6 +291,15 @@ class UpgradeThread(QObject):
274291

275292
# Url = 'https://raw.githubusercontent.com/IronyYou/test/master/Update/Upgrade.json'
276293
# ZipUrl = 'https://raw.githubusercontent.com/IronyYou/test/master/Update/Upgrade.{}.zip'
294+
295+
@classmethod
296+
def quit(cls):
297+
"""退出线程
298+
:param cls:
299+
"""
300+
if hasattr(cls, '_thread'):
301+
cls._thread.quit()
302+
AppLog.info('upgrade thread quit')
277303

278304
@classmethod
279305
def start(cls, parent=None):
@@ -336,6 +362,7 @@ def run(self):
336362
AppLog.info(req.text)
337363
if req.status_code != 200:
338364
AppLog.info('update thread end')
365+
UpgradeThread.quit()
339366
return
340367
content = req.json()
341368
for version, text in content:
@@ -354,3 +381,4 @@ def run(self):
354381
self.tr('update failed: {}').format(str(e)))
355382
AppLog.exception(e)
356383
AppLog.info('update thread end')
384+
UpgradeThread.quit()

0 commit comments

Comments
 (0)