Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.stats_endpoint = global_options['stats_endpoint']
if self.endpoint.startswith('tcp://'):
# In case of multi interface binding i.e: tcp://0.0.0.0:5557
anyaddr = '0.0.0.0'
ip = self.endpoint.lstrip('tcp://').split(':')[0]
self.stats_endpoint = self.stats_endpoint.replace(anyaddr, ip)
# Pub Sub endpoints
self.pubsub_endpoint = global_options['pubsub_endpoint']
if self.endpoint.startswith('tcp://'):
# In case of multi interface binding i.e: tcp://0.0.0.0:5557
anyaddr = '0.0.0.0'
ip = self.endpoint.lstrip('tcp://').split(':')[0]
self.pubsub_endpoint = self.pubsub_endpoint.replace(
anyaddr, ip)
except CallError:
self.connected = False
raise
def timeout_callback():
stream.stop_on_recv()
stream.close()
raise CallError('Call timeout for cmd', cmd)
def _call(self, command, **props):
message = {"command": command, "properties": props or {}}
try:
res = self._client.call(message)
except (CallError) as callerr:
LOG.debug("Error from circus", exc_info=True)
raise CircusException("Could send message to circus: {}".format(callerr))
if res['status'] == u'error':
raise CircusException("Error: {}".format(res['reason']))
return res
timeout = self.loop.add_timeout(timedelta(seconds=5),
timeout_callback)
def recv_callback(msg):
self.loop.remove_timeout(timeout)
stream.stop_on_recv()
stream.close()
callback(json.loads(msg[0]))
stream.on_recv(recv_callback)
try:
socket.send(cmd)
except zmq.ZMQError as e:
raise CallError(str(e))
if not callback:
return json.loads(socket.recv())
try:
if isinstance(msg, list):
for i, c in enumerate(msg):
rc, clm = self._console(client, c['cmd'], opts, c['msg'])
if not rc:
print("%s: %s" % (i, clm))
else:
retcode = rc
sys.stderr.write("%s: %s\n" % (i, clm))
else:
retcode, output = self._console(client, command, opts, msg)
if not retcode:
print(output)
else:
sys.stderr.write(output + '\n')
except CallError as e:
msg = str(e)
if 'timed out' in str(e).lower():
msg += TIMEOUT_MSG
sys.stderr.write(msg)
return 1
finally:
if endpoint is not None:
client.stop()
return retcode
self.socket.send(cmd)
except zmq.ZMQError, e:
raise CallError(str(e))
while True:
try:
events = dict(self.poller.poll(self.timeout))
except zmq.ZMQError as e:
if e.errno == errno.EINTR:
continue
else:
print str(e)
raise CallError(str(e))
if len(events) == 0:
raise CallError("Timed out.")
for socket in events:
msg = socket.recv()
try:
res = json.loads(msg)
if res.get('id') != call_id:
# we got the wrong message
continue
return res
except ValueError as e:
raise CallError(str(e))
def timeout_callback():
stream.stop_on_recv()
stream.close()
raise CallError('Call timeout for cmd', cmd)
def call(self, cmd):
if isinstance(cmd, string_types):
raise DeprecationWarning('call() takes a mapping')
call_id = uuid.uuid4().hex
cmd['id'] = call_id
try:
cmd = json.dumps(cmd)
except ValueError as e:
raise CallError(str(e))
try:
self.socket.send(cmd)
except zmq.ZMQError, e:
raise CallError(str(e))
while True:
try:
events = dict(self.poller.poll(self.timeout))
except zmq.ZMQError as e:
if e.errno == errno.EINTR:
continue
else:
print str(e)
raise CallError(str(e))
timeout = self.loop.add_timeout(timedelta(seconds=5),
timeout_callback)
def recv_callback(msg):
self.loop.remove_timeout(timeout)
stream.stop_on_recv()
stream.close()
callback(json.loads(msg[0]))
stream.on_recv(recv_callback)
try:
socket.send(cmd)
except zmq.ZMQError, e:
raise CallError(str(e))
if not callback:
return json.loads(socket.recv())