@@ -38,9 +38,17 @@ class LoggerLibOpenShot(Thread):
38
38
def __init__ (self ):
39
39
super ().__init__ ()
40
40
self .daemon = True
41
+ self .running = False
42
+ self .context = None
43
+ self .socket = None
44
+
41
45
42
46
def kill (self ):
43
47
self .running = False
48
+ if self .context :
49
+ self .context .destroy ()
50
+ if self .socket :
51
+ self .socket .close ()
44
52
45
53
def run (self ):
46
54
# Running
@@ -63,23 +71,25 @@ def run(self):
63
71
openshot .ZmqLogger .Instance ().Enable (debug_enabled )
64
72
65
73
# Socket to talk to server
66
- context = zmq .Context ()
67
- socket = context .socket (zmq .SUB )
68
- socket .setsockopt_string (zmq .SUBSCRIBE , '' )
74
+ self . context = zmq .Context ()
75
+ self . socket = self . context .socket (zmq .SUB )
76
+ self . socket .setsockopt_string (zmq .SUBSCRIBE , '' )
69
77
70
78
poller = zmq .Poller ()
71
- poller .register (socket , zmq .POLLIN )
79
+ poller .register (self . socket , zmq .POLLIN )
72
80
73
81
log .info ("Connecting to libopenshot with debug port: %s" % port )
74
- socket .connect ("tcp://localhost:%s" % port )
82
+ self . socket .connect ("tcp://localhost:%s" % port )
75
83
76
84
while self .running :
77
85
msg = None
78
86
79
87
# Receive all debug message sent from libopenshot (if any)
80
- socks = dict (poller .poll (1000 ))
81
- if socks and socks .get (socket ) == zmq .POLLIN :
82
- msg = socket .recv (zmq .NOBLOCK )
83
-
84
- if msg :
85
- log .info (msg .strip ().decode ('UTF-8' ))
88
+ try :
89
+ socks = dict (poller .poll (1000 ))
90
+ if socks and socks .get (self .socket ) == zmq .POLLIN :
91
+ msg = self .socket .recv (zmq .NOBLOCK )
92
+ if msg :
93
+ log .info (msg .strip ().decode ('UTF-8' ))
94
+ except Exception as ex :
95
+ log .warning (ex )
0 commit comments