Utilities/BackgroundClient.py

Sat, 05 Jul 2014 15:02:45 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 15:02:45 +0200
changeset 3682
2543741b47b7
parent 3591
2f2a4a76dd22
child 3741
b65577e5c8c6
permissions
-rw-r--r--

Changed a few files to reference eric6.

3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
3 # Copyright (c) 2013 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
4 #
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
5 # pylint: disable=C0103
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
6
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
7 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
8 Module implementing a Qt free version of a background client for the various
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
9 checkers and other python interpreter dependent functions.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
10 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
11
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
12 from __future__ import unicode_literals
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
13 try:
3209
c5432abceb25 CodeStyleChecker moved to background service and done a little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3173
diff changeset
14 bytes = unicode
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
15 import StringIO as io # __IGNORE_EXCEPTION__
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
16 except NameError:
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
17 import io # __IGNORE_WARNING__
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
18
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
19 import json
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
20 import socket
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
21 import struct
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
22 import sys
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
23 import traceback
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
24 from zlib import adler32
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
25
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
26
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
27 class BackgroundClient(object):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
28 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
29 Class implementing the main part of the background client.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
30 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
31 def __init__(self, host, port):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
32 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
33 Constructor of the BackgroundClient class.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
34
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
35 @param host ip address the background service is listening
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
36 @param port port of the background service
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
37 """
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
38 self.services = {}
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
39
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
40 self.connection = socket.create_connection((host, port))
3241
957673fc463a Interface for adding different languages to the syntax check, background service
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3209
diff changeset
41 ver = b'Python2' if sys.version_info[0] == 2 else b'Python3'
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
42 self.connection.sendall(ver)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
43
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
44 def __initClientService(self, fn, path, module):
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
45 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3540
diff changeset
46 Private method to import the given module and register it as service.
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
47
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
48 @param fn service name to register (str)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
49 @param path contains the path to the module (str)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
50 @param module name to import (str)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
51 @return text result of the import action (str)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
52 """
3540
b83fe0651bfd Fixed issue in background service if module is already installed in sys.path.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3444
diff changeset
53 sys.path.insert(1, path)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
54 try:
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
55 importedModule = __import__(module, globals(), locals(), [], 0)
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
56 self.services[fn] = importedModule.initService()
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
57 return 'ok'
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
58 except ImportError:
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
59 return 'Import Error'
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
60
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
61 def __send(self, fx, fn, data):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
62 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
63 Private method to send a job response back to the BackgroundService.
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
64
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
65 @param fx remote function name to execute (str)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
66 @param fn filename for identification (str)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
67 @param data return value(s) (any basic datatype)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
68 """
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
69 packedData = json.dumps([fx, fn, data])
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
70 if sys.version_info[0] == 3:
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
71 packedData = bytes(packedData, 'utf-8')
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
72 header = struct.pack(
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
73 b'!II', len(packedData), adler32(packedData) & 0xffffffff)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
74 self.connection.sendall(header)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
75 self.connection.sendall(packedData)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
76
3444
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
77 def __receive(self, length):
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
78 """
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
79 Private methode to receive the given length of bytes.
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
80
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
81 @param length bytes to receive (int)
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
82 @return received bytes or None if connection closed (str)
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
83 """
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
84 data = b''
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
85 while len(data) < length:
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
86 newData = self.connection.recv(length - len(data))
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
87 if not newData:
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
88 return None
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
89 data += newData
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
90 return data
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
91
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
92 def run(self):
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
93 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3540
diff changeset
94 Public method implementing the main loop of the client.
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
95 """
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
96 try:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
97 while True:
3444
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
98 header = self.__receive(8)
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
99 # Leave main loop if connection was closed.
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
100 if not header:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
101 break
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
102
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
103 length, datahash = struct.unpack(b'!II', header)
3444
118cb489304d Bugfix to avoid hanging Eric5 on shutdown.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3417
diff changeset
104 packedData = self.__receive(length)
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
105
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
106 assert adler32(packedData) & 0xffffffff == datahash, \
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
107 'Hashes not equal'
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
108 if sys.version_info[0] == 3:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
109 packedData = packedData.decode('utf-8')
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
110
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
111 fx, fn, data = json.loads(packedData)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
112 if fx == 'INIT':
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
113 ret = self.__initClientService(fn, *data)
3173
1fb284abe46e Interface to add user-defined services, e.g. in plugins. Auto syntax check working. Little cleanup.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3159
diff changeset
114 else:
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
115 callback = self.services.get(fx)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
116 if callback:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
117 ret = callback(fn, *data)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
118 else:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
119 ret = 'Unknown service.'
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
120
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
121 self.__send(fx, fn, ret)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
122 except:
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
123 exctype, excval, exctb = sys.exc_info()
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
124 tbinfofile = io.StringIO()
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
125 traceback.print_tb(exctb, None, tbinfofile)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
126 tbinfofile.seek(0)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
127 tbinfo = tbinfofile.read()
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
128 del exctb
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
129 self.__send(
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
130 'EXCEPTION', '?', [str(exctype), str(excval), tbinfo])
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
131
3417
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
132 self.connection.shutdown(socket.SHUT_RDWR)
5a93c6cdc989 Exception handling for client side implemented.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3241
diff changeset
133 self.connection.close()
3159
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
134
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
135 if __name__ == '__main__':
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
136 if len(sys.argv) != 3:
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
137 print('Host and port parameters are missing. Abort.')
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
138 sys.exit(1)
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
139
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
140 host, port = sys.argv[1:]
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
141 backgroundClient = BackgroundClient(host, int(port))
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
142 # Start the main loop
02cb2adb4868 First implementation for the BackgroundService.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
143 backgroundClient.run()

eric ide

mercurial