Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from broker.ttypes import Result
from socket_zmq.thrift_server import TGeventStreamServer
from gevent.greenlet import Greenlet
from setproctitle import setproctitle
class BrokerHandler:
a = '0' * 256
def execute(self, task):
return Result(self.a)
listener = ('localhost', 9090)
handler = BrokerHandler()
processor = Broker.Processor(handler)
server = TGeventStreamServer(listener, processor)
def main():
print 'Starting server'
Greenlet(server.stop).start_later(30)
server.serve_forever()
if __name__ == '__main__':
setproctitle('[server]')
#main()
import cProfile
cProfile.runctx("main()", globals(), locals(), "server.prof")
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from thrift.protocol.TBinaryProtocol import TBinaryProtocolAcceleratedFactory
class BrokerHandler:
a = '0' * 256
def execute(self, task):
return Result(self.a)
listener = ('localhost', 9090)
handler = BrokerHandler()
processor = Broker.Processor(handler)
transport = TSocket.TServerSocket(listener[0], listener[1])
tfactory = TBinaryProtocolAcceleratedFactory()
pfactory = TBinaryProtocolAcceleratedFactory()
# set server
server = TNonblockingServer(processor, transport, tfactory, pfactory)
print 'Starting server'
server.serve()
def main():
processor = TBroker.Processor(BrokerHandler())
worker = factory.Worker(processor)
worker.run()