def __init__(self, host, port): super(BaseServer, self).__init__() self.tcp_server = QTcpServer(self) if not self.tcp_server.listen(QHostAddress(host), port): log_error('Unable to start the server: {0}.'.format( self.tcp_server.errorString())) self.exec_() return log_info('The server is running on port {0}.'.format( self.tcp_server.serverPort())) self.connect(self.tcp_server, SIGNAL('newConnection()'), self.new_connection) self.connections = [] self.users = {} self.commands = {} self._add_command('ONLINE', self._command_online) self._add_command('OFFLINE', self._command_offline) self._add_command('ECHO', self._command_echo) self._add_command('USERS', self._command_users)
def _command_from_file(self, client, command, message): commands = message.split("\n") commands = list(filter(lambda x: COMMAND_SPLITER in x, commands)) for command in commands: command, message = [y.strip() for y in str(command).split("|||")] if command == "SET_TYPE": self._command_set_type(client, command, message) elif QString(command) in self.manager_commands: self._command_send_to_manager(client, command, message) elif QString(command) in self.commands: self.commands.get(QString(command))(client, command, message) else: log_error("Not found command", command, message)
def check(self): """проверяет сколько уже в базе значений. и запускает перекладывание в postgresql :return: """ if self.id / self.move_number > self.stored_id / self.move_number: values = [] for x in xrange(self.stored_id, self.stored_id + self.move_number): try: if self.database.get('%s' % x): info = self.database.get('%s' % x).split('\t') channel_id = self.get_id(info[0]) if channel_id is None: # from scripts.python.update_channels import update_list # update_list() # self.kv_storage = load() # channel_id = self.get_id(info[0]) # чтение с диска во время обработки большого потока # приводит к блокировке по диску. raise Exception( 'Not found channel_name in kvstorage: %s' % info[0] ) values.append([info[2], info[1], channel_id]) # time, value, channel_id self.database.delete('%s' % x) except AttributeError as e: log_error(e, x, self.database.get('%s' % x)) self.sql_storage.add(*values) self.stored_id += self.move_number return True return False
def main(): kvstorage = ultramemcache.Client([MEMCACHE_SERVER], debug=0) channels = [] for x in xrange(0, 10): # channels.append('linvac.vacmatrix.Imes%s' % x) channels.append(kvstorage.get('linvac.vacmatrix.Imes%s' % x)) time_start = datetime.datetime(year=2015, month=4, day=1, hour=0, minute=0, second=0, microsecond=0) time_end = datetime.datetime(year=2015, month=4, day=3, hour=0, minute=0, second=0, microsecond=0) data_of_channels = get_data_from_storage(channels, time_start, time_end) check_and_create(os.path.join(MEDIA_FOLDER, 'plots')) for key, value in data_of_channels.items(): try: if value: times, values, np_test = prepare_data(value) name = '%s_%s_%s' % (key, time_start, time_end) show_plot(times, values, np_test, name) except (TypeError, IndexError) as e: log_error(key, e, value) raise
def server_has_error(self): self.send_message('OFFLINE') log_error('Error: {}'.format(self.socket.errorString())) self.socket.close() self.quit()