[rfc] pool test
This commit is contained in:
parent
fe6de66581
commit
551b1a8401
3
main.py
3
main.py
@ -35,6 +35,8 @@ def main():
|
||||
|
||||
world.add_component(
|
||||
session, net_components.NetworkInterface(context=instance_context))
|
||||
world.add_component(
|
||||
session, net_components.User(role=instance_role))
|
||||
|
||||
# A dummy main loop:
|
||||
try:
|
||||
@ -42,7 +44,6 @@ def main():
|
||||
# Call world.process() to run all Processors.
|
||||
world.process()
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
return
|
||||
|
||||
|
@ -24,8 +24,10 @@ class NetworkInterface:
|
||||
self.host = host
|
||||
self.context = context
|
||||
self.socket = context.socket(socket_type)
|
||||
|
||||
self.poller = zmq.Poller()
|
||||
|
||||
#TODO: Is this right to it here?
|
||||
self.poller.register(self.socket, zmq.POLLIN)
|
||||
self.socket.bind("{}://{}:{}".format(protocol,host,port))
|
||||
|
||||
class Property:
|
||||
|
@ -13,6 +13,8 @@ class NetworkSystem(esper.Processor):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# Initialize poll set
|
||||
|
||||
|
||||
# TODO: Use zmq_poll..
|
||||
def process(self):
|
||||
@ -22,4 +24,17 @@ class NetworkSystem(esper.Processor):
|
||||
net_interface.socket.send(b"Waiting server response")
|
||||
|
||||
if user.role is net_components.Role.SERVER:
|
||||
net_interface.socket.recv(b"Waiting server response")
|
||||
print("Server loops")
|
||||
try:
|
||||
socks = dict(net_interface.poller.poll())
|
||||
print("test")
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
if net_interface.socket in socks:
|
||||
message = net_interface.socket.recv()
|
||||
|
||||
print("test")
|
||||
# process task
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user