def compileResult(VMs): parts = 0 ans = 0 msgs = [] arrays = {} time.sleep(0.2) while parts < VMs: try: print "Getting Query.." string = socket_results.recv() messagedata = string[2:] resp = str(messagedata) print "Appending:", modules.str2arr(resp) msgs.append(resp) parts += 1 except: print("Waiting for Result in Queue qresult") print("\nParts recieved: %d" % (len(msgs))) print modules.str2arr(msgs[0]) print modules.str2arr(msgs[1]) print modules.str2arr(msgs[2]) print modules.str2arr(msgs[3]) for msg in msgs: msg = modules.str2arr(msg) arrays[msg[-1][0]] = msg[:-1] print arrays print combine(arrays)
def fetchMessage(queueName): sqs = boto3.resource('sqs') queue = sqs.get_queue_by_name(QueueName=queueName) client = boto3.client('sqs') # Get URL for SQS queue response = client.receive_message( QueueUrl=queue.url, MaxNumberOfMessages=1, ) # print response try: messages = response['Messages'] for msg in messages: body = msg['Body'] print "Message Received: { %s } from Queue: { %s }" %(modules.str2arr(body), queueName) rhandle = msg['ReceiptHandle'] del_response = client.delete_message( QueueUrl=queue.url, ReceiptHandle=rhandle ) # print del_response return body except: return ""
def processMessage(msg): # print msg msgArray = modules.str2arr(msg) N = (len(msgArray) - 1)/2 elements = [] for i in range(0, (len(msgArray)-1), N/2): elements.append(msgArray[i:i+N/2]) elements = np.array(elements) answer = np.dot(elements[0],elements[1]) + np.dot(elements[2],elements[3]) answer = np.concatenate((answer,[msgArray[-1]]),axis=0) print "ANS"*30 print answer modules.sendToQueue('qresult', modules.arr2str(answer))
def processMessage(msg): # print msg msgArray = modules.str2arr(msg) N = (len(msgArray) - 1) / 2 elements = [] for i in range(0, (len(msgArray) - 1), N / 2): elements.append(msgArray[i:i + N / 2]) elements = np.array(elements) answer = np.dot(elements[0], elements[1]) + np.dot(elements[2], elements[3]) answer = np.concatenate((answer, [msgArray[-1]]), axis=0) print "\nANS:" print answer, "\n" # print (9, modules.arr2str(answer)) socket_results.send("%d %s" % (9, modules.arr2str(answer)))
def compileResult(VMs): parts = 0 ans = 0 msgs = [] arrays = {} while parts < VMs: try: resp = str(slave.fetchMessage('qresult')) print "Appending:", modules.str2arr(resp) msgs.append(resp) parts += 1 except: print("Waiting for Result in Queue qresult") print("\nParts recieved: %d" % (len(msgs))) print modules.str2arr(msgs[0]) print modules.str2arr(msgs[1]) print modules.str2arr(msgs[2]) print modules.str2arr(msgs[3]) for msg in msgs: msg = modules.str2arr(msg) arrays[msg[-1][0]] = msg[:-1] print arrays print combine(arrays) modules.purge_qr()