def main(): print('Loading model...') global sess global graph global vgg_features global image_size gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.1) with tf.Graph().as_default() as graph: with tf.Session(config=tf.ConfigProto( gpu_options=gpu_options)).as_default() as sess: vgg_features = VGGFace(model='resnet50', include_top=False, pooling='avg') # vgg_features = load_model('resnet_model/resnet50.h5') image_size = 224 handler = FaceEmbeddingHandler() processor = FaceEmbedding.Processor(handler) transport = TSocket.TServerSocket(host='0.0.0.0', port=config.SERVER_THRIFT_PORT) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print('READY') try: server.serve() except KeyboardInterrupt: pass
def createServer(self, processor, host, port): socket = TSocket.TServerSocket(host, port) server = TServer.TThreadedServer(processor, socket, self.transportFactory, self.protocolFactory) return server
def serve(port: int, language: str, ner: bool) -> None: coloredlogs.install(stream=sys.stderr, level=logging.INFO, fmt='%(asctime)s %(name)s %(levelname)s %(message)s') logging.info("Loading ...") tagging_nlp = spacy.load(language, disable=['ner']) # type: Language tagging_nlp.remove_pipe('parser') logging.info("Tagging pipeline: %s", ', '.join(tagging_nlp.pipe_names)) ner_nlp = None if ner: ner_nlp = spacy.load(language) # type: Language logging.info("NER pipeline: %s", ', '.join(ner_nlp.pipe_names)) handler = Handler(tagging_nlp, ner_nlp) processor = SpacyThrift.Processor(handler) server_socket = TSocket.TServerSocket(port=port) transport_factory = TTransport.TBufferedTransportFactory() protocol_factory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, server_socket, transport_factory, protocol_factory) logging.info("Serving on port %d ...", port) server.serve()
def start_server_process(self): """ Starts a test server, returns the (pid, port) pair. The server needs to be in a subprocess because we need to run a TThreadedServer for the concurrency tests. And the only way to stop a TThreadedServer is to kill it. So we can't just use a thread. """ self.pid = os.fork() if self.pid != 0: logging.info("Started SimpleThriftServer (pid %s) on port %s" % (self.pid, self.port)) self._ensure_online() return # Child process runs the thrift server loop try: processor = TestService.Processor(self) transport = TSocket.TServerSocket(self.port) server = TServer.TThreadedServer(processor, transport, TBufferedTransportFactory(), TBinaryProtocolFactory()) server.serve() except: sys.exit(1)
def run(self): processor = TMultiplexedProcessor() processor.registerProcessor( "DFSService", DistributedFilesystem.Processor( DistributedFileSystemHandler(self.master.dfs) ) ) processor.registerProcessor( "UserService", MasterUserService.Processor( UserServiceHandler(self.master) ) ) server = TServer.TThreadedServer( processor, TSocket.TServerSocket(self.listen_address, self.listen_port), TTransport.TFramedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory(), daemon=True, ) # Start Tanit distributed filesystem server.serve()
def main(): parser = argparse.ArgumentParser(description='Skype via Apache Thrift.') parser.add_argument('--warmup', action='store_true', help='preload all chats from client') args = parser.parse_args() skype = helpers.init_skype4py() handler = SkypeHandler(skype) processor = Skype.Processor(handler) transport = TSocket.TServerSocket(host='0.0.0.0', port=9090) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory, daemon=True) print("thrift_server: Attaching to Skype") skype.Attach() if args.warmup: print("thrift_server: Warming up chats") map(mappers.remap_chat_object, skype.Chats) print("thrift_server: Serving") server.serve()
def main(): parser = argparse.ArgumentParser(description='TODO') parser.add_argument('-l', '--num_locks', dest='n_locks', required=True, help="Number of mutexes available", type=int) parser.add_argument('-p', '--paxos', required=True, help="paxos handler's ip:port") parser.add_argument('-m', '--myport', type=int, required=True, help="My port") parser.add_argument('-i', '--my_id', type=int, required=True, help="My id") args = parser.parse_args() paxos_host, paxos_port = args.paxos.split(':') paxos = PaxosClient(paxos_host, int(paxos_port)) port = args.myport handler = BrokerHandler(args.n_locks, args.my_id, paxos) processor = Broker.Processor(handler) transport = TSocket.TServerSocket(port=port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print "Starting python server..." server.serve() print "done!"
def get_server(api, handler, port, **kwargs): processor = api.Processor(handler) socket = TSocket.TServerSocket(port=port) tfactory = kwargs.get('transport') or TTransport.TFramedTransportFactory() pfactory = kwargs.get('protocol') or TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, socket, tfactory, pfactory) return server
def echo_server(): mp = TMultiplexedProcessor.TMultiplexedProcessor() mp.registerProcessor("echo", Echoer.Processor(EchoHandler())) transport = TSocket.TServerSocket(port=PORT) tf = TTransport.TFramedTransportFactory() pf = TCompactProtocol.TCompactProtocolFactory() return TServer.TThreadedServer(mp, transport, tf, pf, daemon=True)
def _ServerThread(self): processor = ControllerService.Processor(self._handler) transport = TSocket.TServerSocket(host="0.0.0.0", port=self._port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) server.serve()
def serve(conf_path, storage_factory=None): """This method starts the server. There are two processes, one is an HTTP server that shows and admin interface and the second is a Thrift server that the client code calls. Arguments: `conf_path` - The path to your flawless.cfg file `storage_factory` - You can pass in your own storage class that implements StorageInterface. You must implement storage_cls if you want Flawless to be horizontally scalable, since by default it will just store everything on the local disk. """ flawless.lib.config.init_config(conf_path) # Try and create datadir if it doesn't exist. For instance it might be in /tmp if not os.path.exists(config.data_dir_path): os.makedirs(config.data_dir_path) storage_factory = storage_factory or ( lambda partition: DiskStorage(partition=partition)) # Setup root logger root_logger = logging.getLogger() root_handler = logging.handlers.TimedRotatingFileHandler( filename=config.log_file, when='d', interval=1, backupCount=config.log_days_to_keep) root_logger.setLevel(getattr(logging, config.log_level)) root_logger.addHandler(root_handler) child_pid = os.fork() if child_pid == 0: # Setup HTTP server handler = FlawlessWebServiceHandler(storage_factory=storage_factory) server = SimpleThreadedHTTPServer(('', config.http_port), SimpleRequestHTTPHandler) server.attach_service(handler) server.request_queue_size = 50 try: server.serve_forever() except (KeyboardInterrupt, SystemExit): server.server_close() else: # Setup Thrift server handler = FlawlessThriftServiceHandler(storage_factory=storage_factory) processor = Flawless.Processor(handler) transport = TSocket.TServerSocket(port=config.port) tfactory = TTransport.TFramedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) try: server.serve() except (KeyboardInterrupt, SystemExit): handler.errors_seen.sync() transport.close() os.kill(child_pid, signal.SIGINT)
def serverStart(self, port1): self.managerThread = threading.Thread(target=self.managerProc) self.managerThread.setDaemon(True) self.managerThread.start() processor = CAEnginee.Processor(self) self.serverTP = TSocket.TServerSocket(port=port1) self.server = TServer.TThreadedServer(processor, self.serverTP, self.tfactory, self.pfactory)
def run(self): handler = KnnServiceHandler() processor = KnnThriftService.Processor(handler) transport = TSocket.TServerSocket(port=misc_config['port']) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print "Starting python server..." server.serve()
def main(): handler = MapWorldHandler() processor = MapWorldService.Processor(handler) transport = TSocket.TServerSocket(host='127.0.0.1', port=8888) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print('Server started.') server.serve()
def start_service_handler(self): handler = BlockchainServiceHandler(self) processor = BlockchainService.Processor(handler) transport = TSocket.TServerSocket(port=self.port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) logger().info('starting server...') server.serve() logger().info('server started.')
def main(): handler = kvsequence() processor = SequenceService.Processor(handler) transport = TSocket.TServerSocket(port=10100) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print("Starting Server: %s" % host) server.serve() print("Done.")
def run(self): for item in ServiceHandler.get_processor(): self.set_processor(item) print("Serving the Wrapper listener, port: " + str(self.config.get('port'))) return TServer.TThreadedServer( self.processor, self.transport, TTransport.TBufferedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory())
def wrapWorker(impl): processor = QbeastWorker.Processor(impl) transport = TSocket.TServerSocket(port=2688) tfactory = TTransport.TFramedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = IgnoreServer( TServer.TThreadedServer(processor, transport, tfactory, pfactory)) t = Process(target=server.serve) t.daemon = True t.start() return server, t
def Listen(self, port): handler = self.T() processor = self.P(handler) #注意传入参数的时候一定要用port=port,否则port就被为ip了,就会报属性错误 transport = TSocket.TServerSocket(port=port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() #这个是单线程的服务器 #server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) server.serve()
def runManageHandler(accounts, accounts_lock, port): handler = ManageHandler(accounts, accounts_lock) processor = ManageService.Processor(handler) transport = TSocket.TServerSocket(host='127.0.0.1', port=port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print('Starting manage server.') server.serve() print('Manage server done.')
def main(): port = 4242 ip = '127.0.0.1' handler = GameMessagePass() processor = MsgPass.Processor(handler) transport = TSocket.TServerSocket(host=ip, port=port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print("Start Server") server.serve() print("Server Done")
def startServer(self): processor = ping_pong.ping_pong.Processor(self) transport = TSocket.TServerSocket(host=self.my_address, port=self.my_port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print 'Starting the server...' server.serve() print 'done.'
def _run(self): # Create Service handler handler = LocalFileSystemHandler() server = TServer.TThreadedServer( LocalFilesystem.Processor(handler), TSocket.TServerSocket(self.bind_address, self.bind_port), TTransport.TBufferedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory(), daemon=True, ) server.serve()
def server(saas, handler, host=None, port=SAAS_PORT, allowed_ips=None): processor = saas.Processor(handler) # transport = TServerSocket(host, port=SAAS_PORT) # transport = TSSLServerSocket(host, port=SAAS_PORT, certfile=SSL_CERT) sock = MySSLServerSocket(host, port=port, certfile=SSL_CERT, allowed_ips=allowed_ips) #tfactory = TTransport.TBufferedTransportFactory() tfactory = TTransport.TFramedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() #server = TServer.TSimpleServer(processor, sock, tfactory, pfactory) # which cannot deal with exception correctly server = TServer.TThreadedServer(processor, sock, tfactory, pfactory) #server = TServer.TThreadPoolServer(processor, sock, tfactory, pfactory) # which will hang and only be kill by signal 9 server.serve()
def _run(self): # Create Service handler handler = WorkerServiceHandler(self.worker) server = TServer.TThreadedServer( WorkerService.Processor(handler), TSocket.TServerSocket(self.bind_address, self.bind_port), TTransport.TBufferedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory(), daemon=True, ) # Start Tanit server server.serve()
def runStandardHandler(currency_rates, currency_rates_lock, accounts, accounts_lock, port): handler = StandardHandler(accounts, accounts_lock, currency_rates, currency_rates_lock) processor = PremiumService.Processor(handler) transport = TSocket.TServerSocket(host='127.0.0.1', port=port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print('Starting standard server.') server.serve() print('Manage server done.')
def run(self): # Create Service handler handler = WorkerServiceHandler(self.master) server = TServer.TThreadedServer( MasterWorkerService.Processor(handler), TSocket.TServerSocket(self.listen_address, self.listen_port), TTransport.TFramedTransportFactory(), TBinaryProtocol.TBinaryProtocolFactory(), daemon=True, ) # Start Tanit server server.serve()
def main(self): self.set_proctitle(self.name) self.set_exit_handler() try: handler = StateServiceHandler(self) processor = StateService.Processor(handler) transport = TSocket.TServerSocket(self.host, self.port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() # In order to accept multiple simultaneous clients, we use TThreadedServer server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) server.serve() except: logger.error("Error while trying to launch TSCA module")
def serve_service(service, handler, host='127.0.0.1',port=None, is_discovery=False): if is_discovery: from tgen.discovery import Discovery, ttypes as o else: from lib.discovery import Discovery, o PORT_MIN = 9192 PORT_MAX = 10999 if not port and not is_discovery: # choose a random port port = random.randint(PORT_MIN,PORT_MAX) elif not port and is_discovery: # if we are discovery .. user our details port = DISCOVERY_PORT host = DISCOVERY_HOST processor = getattr(service,'Processor')(handler) transport = TSocket.TServerSocket(host,port) tfactory = TTransport.TBufferedTransportFactory() pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print 'registering server: %s %s %s' % ( service.__name__,host,port) # register our service w/ the discovery service if not is_discovery: with connect_discovery() as discovery_client: service_details = o.Service( host=host, port=port, name=service.__name__.split('.')[-1] ) discovery_client.register_service(service_details) print 'starting: %s %s %s' % (service,host,port) try: server.serve() finally: # tell the discovery service we're gone if not is_discovery: print 'removing service from discovery' with connect_discovery() as discovery_client: discovery_client.remove_service(service_details) print 'done'
def runAccountsHandler(currency_rates, currency_rates_lock, accounts, accounts_lock, port): standard_handler = StandardHandler(accounts, accounts_lock, currency_rates, currency_rates_lock) premium_handler = PremiumHandler(accounts, accounts_lock, currency_rates, currency_rates_lock) processor = TMultiplexedProcessor() processor.registerProcessor("PremiumService", PremiumService.Processor(premium_handler)) processor.registerProcessor("StandardService", StandardService.Processor(standard_handler)) transport = TSocket.TServerSocket(host='127.0.0.1', port=port) server = TServer.TThreadedServer(processor, transport) print('Starting accounts server.') server.serve()