本文整理汇总了Python中nanomsg.Socket.configure方法的典型用法代码示例。如果您正苦于以下问题:Python Socket.configure方法的具体用法?Python Socket.configure怎么用?Python Socket.configure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nanomsg.Socket
的用法示例。
在下文中一共展示了Socket.configure方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import configure [as 别名]
def main():
ap = argparse.ArgumentParser()
ap.add_argument('-n', '--rate-limit', metavar="NUM",
help="Number of requests to issue per second (default %(default)d)",
default=100, type=float)
ap.add_argument('-m', '--max-value', metavar="NUM",
help="Maximum number that's sent for factorizing (default %(default)d)",
default=10**12, type=int)
ap.add_argument('--min-value', metavar="NUM",
help="Maximum number that's sent for factorizing (default %(default)d)",
default=10**11, type=int)
ap.add_argument('--topology', metavar="URL", required=True,
help="Url for topology to join to")
options = ap.parse_args()
delay = 1.0 / options.rate_limit
sock = Socket(PUSH)
sock.set_string_option(SOL_SOCKET, SOCKET_NAME, "push")
sock.configure(options.topology)
while True:
tm = time.time()
num = random.randint(options.min_value, options.max_value)
sock.send(str(num))
to_sleep = tm + delay - time.time()
if to_sleep > 0:
time.sleep(to_sleep)
示例2: main
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import configure [as 别名]
def main():
ap = argparse.ArgumentParser()
ap.add_argument('-n', '--requests', metavar="NUM",
help="Number of requests to issue (default %(default)d)",
default=10000, type=int)
ap.add_argument('-c', '--concurrent', metavar="NUM",
help="Number of requests sent simultaneously (default %(default)d)",
default=1000, type=int)
ap.add_argument('-m', '--max-value', metavar="NUM",
help="Maximum number that's sent for factorizing (default %(default)d)",
default=10**12, type=int)
ap.add_argument('--min-value', metavar="NUM",
help="Maximum number that's sent for factorizing (default %(default)d)",
default=10**11, type=int)
ap.add_argument('--topology', metavar="URL", required=True,
help="Url for topology to join to")
options = ap.parse_args()
sock = Socket(REQ, domain=AF_SP_RAW)
sock.set_string_option(SOL_SOCKET, SOCKET_NAME, "client")
sock.configure(options.topology)
start_time = time.time()
reqiter = requests(options)
req = {}
for i in range(options.concurrent):
rid, val = next(reqiter)
sock.send(b'\x00\x00\x00\x00' + struct.pack('>L', rid | 0x80000000)
+ str(val).encode('ascii'))
req[rid] = val
errors = 0
sp = 0
n = 0
while req:
data = sock.recv()
rid = struct.unpack_from('>L', data)[0] & ~0x80000000
factors = map(int, data[4:].decode('ascii').split(','))
checkval = reduce(int.__mul__, factors)
if rid not in req:
sp += 1
elif req.pop(rid) != checkval:
errors += 1
else:
n += 1
try:
rid, val = next(reqiter)
except StopIteration:
continue
else:
sock.send(b'\x00\x00\x00\x00' + struct.pack('>L', rid | 0x80000000)
+ str(val).encode('ascii'))
req[rid] = val
sec = time.time() - start_time
print("Done", options.requests, "requests in", sec,
"seconds, errors:", errors, ", spurious messages:", sp)
示例3: main
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import configure [as 别名]
def main():
ap = argparse.ArgumentParser()
ap.add_argument('--topology', metavar="URL", required=True,
help="Url for topology to join to")
options = ap.parse_args()
sock = Socket(PULL)
sock.set_string_option(SOL_SOCKET, SOCKET_NAME, "push")
sock.configure(options.topology)
while True:
data = sock.recv()
num, factors = data.decode('ascii').split('=', 1)
factors = map(int, factors.split('*'))
checkval = reduce(int.__mul__, factors)
assert int(num) == checkval
示例4: main
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import configure [as 别名]
def main():
ap = argparse.ArgumentParser()
gr = ap.add_mutually_exclusive_group()
gr.add_argument('--rep', metavar="URL",
help="The topology url of replier socket")
gr.add_argument('--pullpush', metavar="URL", nargs=2,
help="The topology urls of pull and push sockets for request processing")
options = ap.parse_args()
if options.rep:
sock = Socket(REP)
sock.configure(options.rep)
sock.set_string_option(SOL_SOCKET, SOCKET_NAME, "rep")
read = write = sock
else:
read = Socket(PULL)
read.set_string_option(SOL_SOCKET, SOCKET_NAME, "pull")
write = Socket(PUSH)
write.set_string_option(SOL_SOCKET, SOCKET_NAME, "push")
read.configure(options.pullpush[0])
write.configure(options.pullpush[1])
while True:
num = int(read.recv())
res = factorize_naive(num)
formula = str(num) + '=' + '*'.join(map(str, res))
write.send(formula.encode('ascii'))