Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import simplejson as json
import zmq
ctx = zmq.Context()
subscriber = ctx.socket(zmq.SUB)
subscriber.linger = 0
subscriber.setsockopt(zmq.SUBSCRIBE, b'')
subscriber.connect("tcp://localhost:5557")
while True:
sequence = int(subscriber.recv())
entry = json.loads(subscriber.recv_string())
print('{}: {}'.format(sequence, entry))
def cleanup():
databases.close()
zmq.Context.instance().term()
logger.info("Exited")
exit()
def Handler(signal, frame):
sys.exit(0)
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--daemonize", help="daemonize the process", action="store_true")
args = parser.parse_args()
if args.daemonize and 'STACKDEBUG' not in os.environ:
lock = lockfile.pidlockfile.PIDLockFile('/var/run/%s/%s.pid' %
('smq-publisher', 'smq-publisher'))
daemon.DaemonContext(pidfile=lock).open()
context = zmq.Context()
publisher = Publisher(context, stack.mq.ports.subscribe)
publisher.setDaemon(True)
publisher.start()
signal.signal(signal.SIGINT, Handler)
signal.pause()
hwm (int): ZMQ high-water mark (buffer size)
format (str): The serialization format.
Default format uses :mod:`tensorpack.utils.serialize`.
This format works with :class:`dataflow.RemoteDataZMQ`.
An alternate format is 'zmq_ops', used by https://github.com/tensorpack/zmq_ops
and :class:`input_source.ZMQInput`.
bind (bool): whether to bind or connect to the endpoint address.
"""
assert format in [None, 'zmq_op', 'zmq_ops']
if format is None:
dump_fn = dumps
else:
from zmq_ops import dump_arrays
dump_fn = dump_arrays
ctx = zmq.Context()
socket = ctx.socket(zmq.PUSH)
socket.set_hwm(hwm)
if bind:
socket.bind(addr)
else:
socket.connect(addr)
try:
df.reset_state()
logger.info("Serving data to {} with {} format ...".format(
addr, 'default' if format is None else 'zmq_ops'))
INTERVAL = 200
q = deque(maxlen=INTERVAL)
try:
total = df.size()
except NotImplementedError:
#!/usr/bin/env python
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer, AuthenticationFailed
import zmq
import os
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://127.0.0.1:2122")
HOST = '0.0.0.0'
PORT = 2121
ZMQ_PORT = 2122
USERNAME = 'john'
PASSWORD = 'snow'
HOMEDIR = os.path.expanduser('~/.config/tero') # only Linux
class FTPAuthorizer(DummyAuthorizer):
user_table = {}
def validate_authentication(self, username, password, handler):
if not (username == USERNAME and password == PASSWORD):
def rep_server(process, host, port):
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://" + host + ":" + str(port))
print("listening on: %s:%d" % (host, port))
while True:
message = socket.recv()
# print("received [%d]: %s" % (port, message))
event = json.loads(message)
socket.send(json.dumps(process(event)))
def fake_multisignal_mainLoop(stop_flag, stream, precomputed):
import zmq
pos = 0
abs_pos = pos2 = 0
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:{}".format(stream['port']))
socket.send(msgpack.dumps(abs_pos))
packet_size = stream['packet_size']
sampling_rate = stream['sampling_rate']
np_arr = stream['shared_array'].to_numpy_array()
half_size = np_arr.shape[1]/2
while True:
t1 = time.time()
#~ print 'pos', pos, 'abs_pos', abs_pos
#double copy
np_arr[:,pos2:pos2+packet_size] = precomputed[:,pos:pos+packet_size]
np_arr[:,pos2+half_size:pos2+packet_size+half_size] = precomputed[:,pos:pos+packet_size]
pos += packet_size
from flask_sqlalchemy import SQLAlchemy
from config import zeromq_relay_uri
import zmq
db = SQLAlchemy()
zmq_relay_socket = None
zeromq_context = None
if zeromq_relay_uri:
zeromq_context = zmq.Context()
zmq_relay_socket = zeromq_context.socket(zmq.PUSH)
zmq_relay_socket.connect(zeromq_relay_uri)
def send_ctrl_message(address: str, msg: 'gnes_pb2.Message', timeout: int):
# control message is short, set a timeout and ask for quick response
with zmq.Context() as ctx:
ctx.setsockopt(zmq.LINGER, 0)
sock, _ = build_socket(ctx, address, None, SocketType.PAIR_CONNECT)
send_message(sock, msg, timeout)
r = None
try:
r = recv_message(sock, timeout)
except TimeoutError:
pass
finally:
sock.close()
return r
#!/usr/bin/env python
"""This launches an echoing rep socket device,
and runs a blocking numpy action. The rep socket should
remain responsive to pings during this time."""
import time
import numpy
import zmq
ctx = zmq.Context()
# rep = ctx.socket(zmq.REP)
# rep.bind('tcp://127.0.0.1:10111')
dev = zmq.ThreadsafeDevice(zmq.FORWARDER, zmq.REP, -1)
print "b"
dev.bind_in('tcp://127.0.0.1:10111')
dev.setsockopt_in(zmq.IDENTITY, "whoda")
dev.start()
print "c"
#wait for connections
time.sleep(1)
A = numpy.random.random((2**11,2**12))
print "starting blocking loop"