1
+ import logging
1
2
import socket
2
- from datetime import datetime
3
3
from threading import Thread , RLock , Event
4
4
5
5
from mprotocol_client_python .ProtocolResult import ProtocolResult
6
6
from mprotocol_client_python .NodeProperty import NodeProperty
7
7
8
8
9
- def DEBUG_PRINT (message ):
10
- print ('[%s] %s' % (datetime .now ().strftime ('%H:%M:%S' ), message ))
11
-
12
-
13
9
## MProtocol client class
14
10
#
15
11
# Manages connection to the remote device and is the interface for data exchange
@@ -128,7 +124,7 @@ def remove_subscription(self, callback, node_path, property_name=None):
128
124
129
125
## Background thread that handles incoming traffic
130
126
def thread_function (self ):
131
- DEBUG_PRINT ( 'starting thread' )
127
+ logging . info ( 'Starting client thread' )
132
128
while True :
133
129
try :
134
130
received_bytes = self .socket .recv (4096 )
@@ -137,11 +133,11 @@ def thread_function(self):
137
133
self .process_received_str ()
138
134
else :
139
135
# recv() returns empty string if the remote side has closed the connection
140
- DEBUG_PRINT ( 'finishing thread (empty recv )' )
136
+ logging . info ( 'Finishing thread (server closed )' )
141
137
break
142
138
except Exception as e :
143
139
# remote side will not be sending more data after connection errors
144
- DEBUG_PRINT ( 'finishing thread (exception:%s)' % str (e ))
140
+ logging . error ( 'Finishing thread (exception:%s)' % str (e ))
145
141
break
146
142
147
143
# close and delete socket so that it won't be used again
@@ -181,7 +177,7 @@ def process_received_str(self):
181
177
self .result = ProtocolResult (ProtocolResult .ok_init_str , line [4 :])
182
178
self .response_received_or_error .set ()
183
179
else :
184
- DEBUG_PRINT ('Unable to process response: ' + line )
180
+ logging . warning ('Unable to process response: ' + line )
185
181
186
182
# keep last unfinished line in buffer
187
183
self .received_str = lines [- 1 ]
0 commit comments