eric6/Utilities/BackgroundClient.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8267
6baca884c73a
child 8400
b3eefd7e58d1
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
14 import socket 14 import socket
15 import struct 15 import struct
16 import sys 16 import sys
17 import time 17 import time
18 import traceback 18 import traceback
19 import contextlib
19 from zlib import adler32 20 from zlib import adler32
20 21
21 22
22 class BackgroundClient(object): 23 class BackgroundClient:
23 """ 24 """
24 Class implementing the main part of the background client. 25 Class implementing the main part of the background client.
25 """ 26 """
26 def __init__(self, host, port, maxProcs): 27 def __init__(self, host, port, maxProcs):
27 """ 28 """
58 """ 59 """
59 sys.path.insert(1, path) 60 sys.path.insert(1, path)
60 try: 61 try:
61 importedModule = __import__(module, globals(), locals(), [], 0) 62 importedModule = __import__(module, globals(), locals(), [], 0)
62 self.services[fn] = importedModule.initService() 63 self.services[fn] = importedModule.initService()
63 try: 64 with contextlib.suppress(AttributeError):
64 self.batchServices["batch_" + fn] = ( 65 self.batchServices["batch_" + fn] = (
65 importedModule.initBatchService() 66 importedModule.initBatchService()
66 ) 67 )
67 except AttributeError:
68 pass
69 return 'ok' 68 return 'ok'
70 except ImportError: 69 except ImportError as err:
71 return 'Import Error' 70 return 'Import Error: ' + str(err)
71 except Exception as err:
72 return str(err)
72 73
73 def __send(self, fx, fn, data): 74 def __send(self, fx, fn, data):
74 """ 75 """
75 Private method to send a job response back to the BackgroundService 76 Private method to send a job response back to the BackgroundService
76 server. 77 server.
122 @rtype bytes 123 @rtype bytes
123 """ 124 """
124 data = b'' 125 data = b''
125 self.connection.setblocking(False) 126 self.connection.setblocking(False)
126 try: 127 try:
127 data = self.connection.recv(length, socket.MSG_PEEK) 128 with contextlib.suppress(OSError):
128 except OSError: 129 data = self.connection.recv(length, socket.MSG_PEEK)
129 pass
130 finally: 130 finally:
131 self.connection.setblocking(True) 131 self.connection.setblocking(True)
132 132
133 return data 133 return data
134 134

eric ide

mercurial