Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def Listener():
while True:
gevent.sleep(SLEEP_TIME)
msgs = json.loads(api_Read[i].getAllInboxMessages())['inboxMessages']
for msg in msgs:
receipt_no = i
tmpvar = base64.b64decode(msg['message'])
if tmpvar[:3] == 'HB-':
result = decode(
base64.b64decode(
tmpvar[3:]
)
)
if result:
mylog('[%d] got message %s' % (receipt_no, result))
recvChannel[receipt_no].put((
address.index(msg['fromAddress']), result
))
api_Read[i].trashMessage(msg['msgid'])
def test_lock_out_of_context_pair_2(self):
with raises(GIPCLocked):
with pipe(True) as (h1, h2):
gr = gevent.spawn(lambda h: h.get(), h2)
gevent.sleep(SHORTTIME)
# Context succeeds closing h1 reader and writer. Fails during
# closing h2 reader.
assert not h2._reader._closed
assert h1._reader._closed
assert h2._writer._closed
assert h1._writer._closed
gr.kill(block=False)
gevent.sleep(-1)
h2.close()
def run(q):
# libev only calls fork callbacks at the beginning of
# the loop; we use callbacks extensively so it takes *two*
# calls to sleep (with a timer) to actually get wrapped
# around to the beginning of the loop.
gevent.sleep(0.01)
gevent.sleep(0.01)
q.put(newpid)
server = zerorpc.ChannelMultiplexer(server_events)
client_events = zerorpc.Events(zmq.DEALER)
client_events.connect(endpoint)
client = zerorpc.ChannelMultiplexer(client_events, ignore_broadcast=True)
client_channel = client.channel()
client_hbchan = zerorpc.HeartBeatOnChannel(client_channel, freq=TIME_FACTOR * 2)
client_bufchan = zerorpc.BufferedChannel(client_hbchan)
event = server.recv()
server_channel = server.channel(event)
server_hbchan = zerorpc.HeartBeatOnChannel(server_channel, freq=TIME_FACTOR * 2)
server_bufchan = zerorpc.BufferedChannel(server_hbchan)
gevent.sleep(TIME_FACTOR * 3)
print('CLOSE SERVER SOCKET!!!')
server_bufchan.close()
if sys.version_info < (2, 7):
assert_raises(zerorpc.LostRemote, client_bufchan.recv)
else:
with assert_raises(zerorpc.LostRemote):
client_bufchan.recv()
print('CLIENT LOST SERVER :)')
client_bufchan.close()
server.close()
client.close()
stime = int(time.time()*1000)
rawSpan='{"name":"PHP Request",' \
'"server":"10.34.130.79:28081",' \
'"sid":"3345567788","psid":"3345567789","tid":"php-test-1^1560951035971^%d",'\
'"S":%d,"E":20,' \
'"clues":["46:200"],' \
'"uri":"/index.html",' \
'"EC":1, "estr":"DIY",' \
'"calls":[{"name":"hello","S":0,"E":8,"calls":[{"name":"hello2","S":2,"E":2,"clues":["-1:null","14:2019/06/25"],"calls":[{"name":"hello3","S":4,"E":4}]}]}],' \
'"client":"10.10.10.10"}'% (i,stime)
stack = json.loads(rawSpan)
TCLogger.info("%s", stack)
agent.sendSpan(stack)
i += 1
gevent.sleep(10)
g = Event()
g.wait()
def run(self, source=None):
index = 0
if isinstance(source, basestring):
source = [source]
for file in source:
self.message = self.message_template % file
p = subprocess.Popen(self.command + [file])
while p.poll() is None:
gevent.sleep(1)
if self.aborted:
p.terminate()
return
index += 1
self.set_progress(index, len(source))
def _send_result(self, replyq, id_, result=None, error=None):
ans = {
'source': self.name,
'id': id_,
'result': result,
'error': error
}
ans = json.dumps(ans)
msg = amqp.Message(body=ans)
self.channel.basic_publish(msg, routing_key=replyq)
LOG.debug('AMQPRpcServerChannel - sent result %s', ans)
gevent.sleep(0)
canonical_id = list_cannonical_ids[-1]
chain_state = views.state_from_raiden(raiden)
channel_state = views.get_channelstate_by_canonical_identifier(
chain_state=chain_state, canonical_identifier=canonical_id
)
channel_is_settled = (
channel_state is None or channel.get_status(channel_state) in target_states
)
if channel_is_settled:
list_cannonical_ids.pop()
else:
log.debug("wait_for_channel_in_states", **log_details)
gevent.sleep(retry_timeout)
full_url = self.base_uri + request_url
try:
response = self.session.request(
request_method.lower(),
full_url,
data=stringified_options,
)
except requests.exceptions.ConnectionError as e:
raise RemoteError(
f'Coinbase Pro {request_method} query at '
f'{full_url} connection error: {str(e)}',
)
if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
# Backoff a bit by sleeping. Sleep more, the more retries have been made
gevent.sleep(QUERY_RETRY_TIMES / retries_left)
retries_left -= 1
else:
# get out of the retry loop, we did not get 429 complaint
break
json_ret: Union[List[Any], Dict[str, Any]]
if response.status_code == HTTPStatus.BAD_REQUEST:
json_ret = rlk_jsonloads_dict(response.text)
if json_ret['message'] == 'invalid signature':
raise CoinbaseProPermissionError(
f'While doing {request_method} at {endpoint} endpoint the API secret '
f'created an invalid signature.',
)
# else do nothing and a generic remote error will be thrown below
elif response.status_code == HTTPStatus.FORBIDDEN:
self.ready.set()
# Any commands that were in transit when the
# connection was lost is obviously not getting a
# reply. Retransmit them.
self._retransmit_pending()
self.loop = _spawner(self._recv_loop)
return
except IOError, e:
self._logger.info('Failed to connect to %s (%s)', self.address, e)
pass
addrs_left -= 1
self._logger.debug('Waiting %d seconds to reconnect', retry_wait)
gevent.sleep(retry_wait)
retry_wait *= 2
self._logger.error('Could not connect to any of the defined addresses')
raise ConnectError("Can't connect to any of the addresses: %s" % self.addrs)