Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._URL = self._protocol + "://" + self._host + ":"
# Ports for PUSH, PULL and SUB sockets respectively
self._PUSH_PORT = _PUSH_PORT
self._PULL_PORT = _PULL_PORT
self._SUB_PORT = _SUB_PORT
# Handlers for received data (pull and sub ports)
self._pulldata_handlers = _pulldata_handlers
self._subdata_handlers = _subdata_handlers
# Create Sockets
self._PUSH_SOCKET = self._ZMQ_CONTEXT.socket(zmq.PUSH)
self._PUSH_SOCKET.setsockopt(zmq.SNDHWM, 1)
self._PULL_SOCKET = self._ZMQ_CONTEXT.socket(zmq.PULL)
self._PULL_SOCKET.setsockopt(zmq.RCVHWM, 1)
self._SUB_SOCKET = self._ZMQ_CONTEXT.socket(zmq.SUB)
# Bind PUSH Socket to send commands to MetaTrader
self._PUSH_SOCKET.connect(self._URL + str(self._PUSH_PORT))
print("[INIT] Ready to send commands to METATRADER (PUSH): " + str(self._PUSH_PORT))
# Connect PULL Socket to receive command responses from MetaTrader
self._PULL_SOCKET.connect(self._URL + str(self._PULL_PORT))
print("[INIT] Listening for responses from METATRADER (PULL): " + str(self._PULL_PORT))
# Connect SUB Socket to receive market data from MetaTrader
print("[INIT] Listening for market data from METATRADER (SUB): " + str(self._SUB_PORT))
self._SUB_SOCKET.connect(self._URL + str(self._SUB_PORT))
def socket_type(self):
if self.mode == zmq.PULL:
return 'PULL'
elif self.mode == zmq.PUSH:
return 'PUSH'
elif self.mode == zmq.PUB:
return 'PUB'
elif self.mode == zmq.SUB:
return 'SUB'
elif self.mode == zmq.PAIR:
return 'PAIR'
elif self.mode == zmq.REQ:
return 'REQ'
elif self.mode == zmq.REP:
return 'REP'
elif self.mode == zmq.ROUTER:
return 'ROUTER'
elif self.mode == zmq.DEALER:
def __init__(self, backend, *args, **kwargs):
self.context = zmq.Context()
self.backend = self.context.socket(zmq.PULL)
self.backend.connect(backend)
self.recv_func = self.backend.recv_string
def __init__(self, name, send_qsize=0, mode='ipc'):
self._name = name
self._conn_info = None
self._context_lock = threading.Lock()
self._context = zmq.Context()
self._tosock = self._context.socket(zmq.ROUTER)
self._frsock = self._context.socket(zmq.PULL)
self._tosock.set_hwm(10)
self._frsock.set_hwm(10)
self._dispatcher = CallbackManager()
self._send_queue = queue.Queue(maxsize=send_qsize)
self._rcv_thread = None
self._snd_thread = None
self._mode = mode
assert mode in ('ipc', 'tcp')
def create_worker_scoper(settings, mgmt, zmq_context, log_handler, io_loop):
"""
Create and return a new `Worker Scoper` that will check if the newly
extracted URLs are within this crawls scope.
"""
processing = create_processing_function(settings,
settings.SPYDER_SCOPER_PIPELINE)
pulling_socket = zmq_context.socket(zmq.PULL)
pulling_socket.connect(settings.ZEROMQ_WORKER_PROC_SCOPER_PULL)
pushing_socket = zmq_context.socket(zmq.PUB)
pushing_socket.connect(settings.ZEROMQ_WORKER_PROC_SCOPER_PUB)
return ZmqWorker(pulling_socket, pushing_socket, mgmt, processing,
log_handler, settings.LOG_LEVEL_WORKER, io_loop=io_loop)
def __iter__(self):
self.ctx = zmq.Context()
self._consumer = self.ctx.socket(zmq.PULL)
try:
self._producer.start()
self._consumer.connect(self.sock_name)
while True:
try:
flow = self._consumer.recv_pyobj()
if flow is None:
break
else:
yield flow
except KeyboardInterrupt:
if not self._stopped:
self._stopped = True
self.cache.stopped = True
self._consumer.close()
self.ctx.destroy()
print "Response:", response
self.send_response(response, more="0")
self.disconnect()
class ZMQBaseServer(object):
REP = zmq.REP
REQ = zmq.REQ
ROUTER = zmq.ROUTER
DEALER = zmq.DEALER
PUB = zmq.PUB
SUB = zmq.SUB
XPUB = zmq.XPUB
XSUB = zmq.XSUB
PULL = zmq.PULL
PUSH = zmq.PUSH
PAIR = zmq.PAIR
protocol = "tcp"
Channel = ZMQBaseServerChannel
RequestHandlerClass = ZMQWSGIRequestHandler
pattern = None
poller = _Poller()
def __init__(self, listener, app,
context=None, bind=True,
spawn_type=Thread, spawn_size=2,
handler_class=None):
self.listener = listener
self.app = app
self.context = context or zmq.Context.instance()
def __init__(self, pipe_c2s, pipe_s2c):
super(SimulatorMaster, self).__init__()
self.daemon = True
self.name = 'SimulatorMaster'
self.context = zmq.Context()
self.c2s_socket = self.context.socket(zmq.PULL)
self.c2s_socket.bind(pipe_c2s)
self.c2s_socket.set_hwm(10)
self.s2c_socket = self.context.socket(zmq.ROUTER)
self.s2c_socket.bind(pipe_s2c)
self.s2c_socket.set_hwm(10)
# queueing messages to client
self.send_queue = queue.Queue(maxsize=100)
def f():
msg = self.send_queue.get()
self.s2c_socket.send_multipart(msg, copy=False)
self.send_thread = LoopThread(f)
self.send_thread.daemon = True
self.send_thread.start()
def __init__(self, logger, address='tcp://127.0.0.1:*', sort=True):
threading.Thread.__init__(self, daemon=True)
self.logger = logger
self.socket = zmq.Context.instance().socket(zmq.PULL)
self.socket.bind(address)
self.address = self.socket.getsockopt(zmq.LAST_ENDPOINT)
self.serializer = JsonSerializer()
def __init__(self, simulators, pipe_sim2mgr, pipe_mgr2sim):
self.sim2mgr = pipe_sim2mgr
self.mgr2sim = pipe_mgr2sim
self.context = zmq.Context()
self.sim2mgr_socket = self.context.socket(zmq.PULL)
self.sim2mgr_socket.bind(self.sim2mgr)
self.sim2mgr_socket.set_hwm(2)
self.mgr2sim_socket = self.context.socket(zmq.ROUTER)
self.mgr2sim_socket.bind(self.mgr2sim)
self.mgr2sim_socket.set_hwm(2)
self.simulators = simulators
for sim in self.simulators:
ensure_proc_terminate(sim)
self.queue = queue.Queue(maxsize=100)
self.current_sim = None
self.locked_sim = None