Beispiel #1
0
def main(): ####################################################################
	try:
		opts, args = getopt.getopt(sys.argv[1:], "hH:P:p:n:N:d:", ["help", "host=", "profile=", "port=", "nr=", "name=", "delay="])
	except getopt.GetoptError as err:
		print >> sys.stderr, str(err)
		usage()
		sys.exit(2)


	opt_profile	= ''
	opt_port   	= '3001'
	opt_host	= '127.0.0.1'
	opt_nr		= 1000000
	opt_delay	= 1.
	opt_name	= 'Torture - reg/unreg. pid=%d' % os.getpid()

	## parse arguments ##
	for o, a in opts:
		if o in ("-h", "--help"):
			usage()
			sys.exit()
		elif o in ("-P", "--profile"):
			opt_profile = a
		elif o in ("-p", "--port"):
			opt_port = a
		elif o in ("-H", "--host"):
			opt_host = a
		elif o in ("-n", "--name"):
			opt_name = a
		elif o in ("-N", "--nr"):
			opt_nr = int(a
)
		elif o in ("-d", "--delay"):
			opt_delay = float(a)


	c = mb.Client(opt_name)
	t = 0
	for i in xrange(0, opt_nr):
		t += ticked()
		print "\r%02.1f%% %c" % (100.*i/opt_nr, "-/|\\"[t % 4]),
		try:
			c.reg(host=opt_host, port=opt_port, profile=opt_profile)
			if opt_delay: time.sleep(opt_delay)
			c.unreg()
			if opt_delay: time.sleep(opt_delay)
		except:
			pass
Beispiel #2
0
def main(
):  ####################################################################
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hH:P:p:n:N:d:m:", [
            "help", "host=", "profile=", "port=", "nr=", "name=", "delay=",
            "sync", "async", "msg="
        ])
    except getopt.GetoptError as err:
        print >> sys.stderr, str(err)
        usage()
        sys.exit(2)

    opt_profile = ''
    opt_port = '3001'
    opt_host = '127.0.0.1'
    opt_nr = 1000000
    opt_delay = .5
    opt_name = "%s [%d]" % (PROG, os.getpid())
    opt_msgs = []
    opt_async = False

    ## parse arguments ##
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-P", "--profile"):
            opt_profile = a
        elif o in ("-p", "--port"):
            opt_port = a
        elif o in ("-H", "--host"):
            opt_host = a
        elif o in ("-n", "--name"):
            opt_name = a
        elif o in ("-N", "--nr"):
            opt_nr = int(a)
        elif o in ("-d", "--delay"):
            opt_delay = float(a)
        elif o in ("-m", "--msg"):
            opt_msgs.append({'async': opt_async, 'name': a})
        elif o in ("-s", "--sync"):
            opt_async = False
        elif o in ("-a", "--async"):
            opt_async = True

    if not opt_msgs:
        print 'Nothing to do...'
        sys.exit(0)

    have_sync = not reduce(lambda v, msg: v and msg['async'], opt_msgs, True)

    global client

    client = mb.Client(opt_name)
    client.reg(opt_profile)

    # open/subscribe
    for msg in opt_msgs:
        msg['mid'] = client.open(msg['name'], 'rw')
        client.sub(msg['mid'], cb, adaptor=int, async=msg['async'])

    # seed traffic...
    for msg in opt_msgs:
        client.post(msg['mid'], client.id(), 0)

    N = len(opt_msgs) * opt_nr
    p = progress.Progress(N)

    # working cycle/indication
    while n < N:
        print p.indicator(n),

        if have_sync:
            time.sleep(opt_delay)
            client.dispatch(True, 1)

    # close
    for msg in opt_msgs:
        client.close(msg['mid'])

    print p.indicator(n)

    client.unreg()
Beispiel #3
0
        opt_port = a
    elif o in ("-f", "--profile"):
        opt_profile = a
    elif o in ("-s", "--name"):
        opt_name = a
    elif o in ("-s", "--settings"):
        opt_settings = a

txt = None


def cb(m, v):
    global txt
    try:
        print "%sonfiguring = %s" % ("C" if txt is None else "Rec", v)
        txt = v
    except:
        raise


c = mb.Client(opt_name)
c.reg(opt_profile)
m = c.mopen(opt_settings, "r")
c.sub(m, cb, type=str)
c.dispatch(True, 0)

print "Work..."

while True:
    c.dispatch(True, 1000)
Beispiel #4
0
def main(
):  ####################################################################
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hH:P:p:n:N:d:f:m:", [
            "help", "host=", "profile=", "port=", "nr=", "name=", "delay=",
            "flags=", "msg="
        ])
    except getopt.GetoptError as err:
        print >> sys.stderr, str(err)
        usage()
        sys.exit(2)

    opt_profile = ''
    opt_port = '3001'
    opt_host = '127.0.0.1'
    opt_nr = 1000000
    opt_delay = 1
    opt_name = 'Torture - mopen/close. pid=%d' % os.getpid()
    opt_flafs = 'r'
    opt_msg = None

    ## parse arguments ##
    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-P", "--profile"):
            opt_profile = a
        elif o in ("-p", "--port"):
            opt_port = a
        elif o in ("-H", "--host"):
            opt_host = a
        elif o in ("-n", "--name"):
            opt_name = a
        elif o in ("-N", "--nr"):
            opt_nr = int(a)
        elif o in ("-d", "--delay"):
            opt_delay = int(a)

        elif o in ("-f", "--flags"):
            opt_flags = a
        elif o in ("-m", "--msg"):
            opt_msg = a

    c = mb.Client(opt_name)
    c.reg(host=opt_host, port=opt_port, profile=opt_profile)
    c.sub(mb.MD_SYS_NOTIFY_OPEN, on_open_notify)
    t = 0
    for i in xrange(0, opt_nr):
        t += ticked()
        print "\r%02.1f%% %c" % (100. * i / opt_nr, "-/|\\"[t % 4]),
        try:
            m = c.open(opt_msg, opt_flags)
            if opt_delay: time.sleep(opt_delay)
            c.close(m)
        except Exception as e:
            print e
        c.dispatch(True, 1)

    print "\r%02.1f%% %c" % (100. * (i + 1) / opt_nr, "-/|\\"[t % 4])

    c.dispatch(True, 1)
    c.unsub(mb.MD_SYS_NOTIFY_OPEN)
    c.unreg()

    print "open notifications number =", nnr
Beispiel #5
0

def callback(m, v):
    global timer, d, a
    print "m=%r v=%r" % (m, v)
    timer.cancel()
    d = v + opt_amplitude / 2
    a = -opt_amplitude
    ontimer()


def ontimer():
    #	global timer, client, output, d, a
    global timer, d, a
    d, a = d + a, -a
    print "d=%r a=%r" % (d, a)
    client.pub(output, d)
    timer = threading.Timer(opt_period, ontimer)
    timer.start()


with mb.Client(opt_name) as client:
    client.reg(opt_profile, host=opt_host, port=opt_port)
    input = client.mopen(opt_input, "r")
    client.sub(input, callback, type=float)
    output = client.mopen(opt_output, "w")
    timer = threading.Timer(opt_period, ontimer, [client])

    while True:
        client.dispatch(True, 1000)
Beispiel #6
0
            client.post(m, mb.CID_ALL | mb.CID_NOSELF, i)
            output += 1


def work(c):
    global opt_nr, input, output
    print c
    #	while input <= opt_nr:
    #		print "work: input = %d output = %d" % (input, output)
    #		c.dispatch(False, 1000)
    #		time.sleep(opt_timer)
    print "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ input = %d output = %d" % (input,
                                                                        output)


with mb.Client("ping" if bool(opt_ping) else "pong") as c:
    client = c

    c.reg(opt_profile)
    m = c.mopen(opt_ping if bool(opt_ping) else opt_pong, "rw")
    c.sub(m, cb, type=int)

    if bool(opt_ping):
        c.post(m, mb.CID_ALL | mb.CID_NOSELF, 0)

    t = threading.Timer(opt_timer, work, [client])
    t.start()

    while input <= opt_nr:
        c.dispatch(True, 0)
        time.sleep(10)
Beispiel #7
0
    elif o in ("--ping"):
        opt_ping = a
        first = bool(opt_ping) and not bool(opt_pong)
    elif o in ("--pong"):
        opt_pong = a
    elif o in ("-x", "--exclusive"):
        opt_excl = True
    else:
        print >> sys.stderr, "Unknown option:",
        exit(1)

if not (bool(opt_ping) and bool(opt_pong)):
    print >> sys.stderr, "Error: Both ping and pong must be given"
    exit(1)

c = mb.Client("ping" if first else "pong")
c.reg(opt_profile)

print "opening %s as '%s'" % (opt_pong if first else opt_ping,
                              "xw" if opt_excl else "w")
print "opening %s as '%s'" % (opt_ping if first else opt_pong,
                              "xr" if opt_excl else "r")

o = c.mopen(opt_pong if first else opt_ping, "xw" if opt_excl else "w")
i = c.mopen(opt_ping if first else opt_pong, "xr" if opt_excl else "r")

n = 1


def cb(m, v):
    global n