This repository has been archived by the owner on Feb 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyThreads.py
51 lines (42 loc) · 1.5 KB
/
myThreads.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
51
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import threading
import logging
class InterruptThread(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class Thread(threading.Thread):
"""Défini une classe d'objet myThread
Attention! Il faut avoir initialisé un fichier LOG avant !!
"""
def __init__(self, name=None):
threading.Thread.__init__(self)
if name is not None:
self.name = name
self.kill = False
self.stop = False
self.l = logging.getLogger(self.__class__.__name__)
def start(self):
self.run_sav = self.run
self.run = self.myRun
threading.Thread.start(self)
def _stop(self):
self.stop = True
def myRun(self):
try:
self.l.info('Démarrage du myThread - {}'.format(self.getName()))
self.run_sav()
self.run = self.run_sav
if self.kill is True:
raise InterruptThread('Interruption du myThread - {}'.
format(self.getName()))
except InterruptThread:
self.l.exception(('Le myThread - {} a été brutalement arrêté'.
format(self.getName())))
else:
self.l.info(('Le myThread - {} s\'est correctement terminé'.
format(self.getName())))
def kill(self):
self.kill = True