-
Notifications
You must be signed in to change notification settings - Fork 35
/
multithread.py
50 lines (46 loc) · 1.72 KB
/
multithread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# (C) 2019-2021 lifegpc
# This file is part of bili.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from threading import Thread
from typing import Union
def makeSureSendKill(d: Union[dict, list]):
"""确保已经给线程发送了kill"""
if isinstance(d, dict):
for key in d:
t = d[key]
if isinstance(t, Thread):
if hasattr(t, '_mystop') and hasattr(t, 'kill'):
if not t._mystop:
t.kill()
elif isinstance(d, list):
for t in d:
if isinstance(t, Thread):
if hasattr(t, '_mystop') and hasattr(t, 'kill'):
if not t._mystop:
t.kill()
def makeSureAllClosed(d: Union[dict, list]):
"""所有进程是否已经全部退出"""
if isinstance(d, dict):
for key in d:
t = d[key]
if isinstance(t, Thread):
if t.isAlive():
return False
elif isinstance(d, list):
for t in d:
if isinstance(t, Thread):
if t.isAlive():
return False
return True