#!/usr/bin/python3

import sys
import os
import signal

if __name__ == "__main__":
    for chunk_header in sys.stdin:
        os.signal(os.getpid(), signal.SIGTERM)

        chunk_length = int(chunk_header)
        print(str(chunk_length), end="\n")

        while chunk_length != 0:
            line = sys.stdin.readline()
            chunk_length -= 1
            print("Key " + line, end="")

        sys.stdout.flush()
Esempio n. 2
0
 def send_signal(self, sig):
     """
     Send a signal to a subprocess
     """
     os.signal(self.process, sig)
Esempio n. 3
0
 def send_signal(self, sig):
     """
     Send a signal to a subprocess
     """
     os.signal(self.process, sig)
Esempio n. 4
0
    def kill(self):
        if self.killed:
            return

        os.signal(self.pid, signal.SIGTERM)
        self.killed = True
Esempio n. 5
0
def eval_(evalid, cn, duration, rw_ratio):
	hint = 'eval-'+str(evalid)+' with ' + str(cn) + ' clients '
	hint = hint + 'for ' + str(duration) + 's under ' + str(rw_ratio*10) +'% w load: '

	bin = 'eval-c'
	#use this if do distributed eval
	#cid = 0
	children = []
	childrenpipe = []
	result = []
	failed = False
	for i in range(cn):
		args = (bin, str(i), str(evalid), str(duration), str(rw_ratio))
		child, pipe_r = spawn(i, bin, args)
		if child == 0:
			failed = True
			#let spawned children go to the end, fail-safe but not fail-fast
			break
		else:
			children.append(child)
			childrenpipe.append(pipe_r)

	if failed:
		for i in children:
			os.signal(i, SIGKILL)
		for i in childrenpipe:
			os.close(i)
		print hint
		print 'fail'
		return False

	#sleep duration time
	if evalid == 2:
		#kill server in 10s
		time.sleep(10)
	else:
		time.sleep(duration)

	if evalid == 2:
		#preconfigurated master
		snodes[1].work('kill')
		kresult = snodes[1].done()
		if kresult != 'ok':
			print 'kill master ' + snodes[1].name + ' fail'
			failed = True
		else:
			print 'kill master ' + snodes[1].name + ' ok'
			#sleep 20 seconds
			time.sleep(15)

	#for eval-2 only
	#zombies
	if failed:
		for i in children:
			os.signal(i, SIGKILL)
		for i in childrenpipe:
			os.close(i)
		print hint
		print 'fail'
		return False

	assert(len(children) == len(childrenpipe))

	for i in range(len(children)):
		pid, status = os.waitpid(children[i], 0)
		if status != 0 or pid != children[i]:
			failed = True
			print 'check child %d status error' % (i,)
			os.close(childrenpipe[i])
#			os.remove('eval-' + str(i) +'.out')
		else:
			result.append(os.read(childrenpipe[i], 100))
			assert(os.read(childrenpipe[i], 100) == '')
			os.close(childrenpipe[i])
#			os.remove('eval-' + str(i) +'.out')

	if (not failed) and (evalid == 2):
		snodes[1].work('getkt')
		killtime = snodes[1].done()
		#anyone is ok
		snodes[0].work('getrt')
		recoverytime = snodes[0].done()
		failovertime = int(recoverytime)-int(killtime)

	print hint,
	if failed:
		print "fail"
		return False
	else:
		print 'ok'
		print result
		finalr = compute(evalid, result, duration)
		print finalr
		opt = ''
		if evalid == 2:
			opt = 'failover time(server-side): '
			opt = opt + str(failovertime*1000) + 'ms'
			print opt
		logresult(hint, result, finalr, opt)
		return True
Esempio n. 6
0
def kill_proc(pid):
    dprint('Kill process '+str(pid))
    os.signal(pid, signal.SIGTERM)
Esempio n. 7
0
    def kill(self):
        if self.killed:
            return

        os.signal(self.pid, signal.SIGTERM)
        self.killed = True