Esempio n. 1
0
def test():
    NUMBER_OF_PROCESSES = 4
    TASKS1 = [(mul, (i, 7)) for i in range(20)]
    TASKS2 = [(plus, (i, 8)) for i in range(10)]

    # Create queues
    task_queue = Queue()
    done_queue = Queue()

    # Submit tasks
    task_queue.putMany(TASKS1)

    # Start worker processes
    for i in range(NUMBER_OF_PROCESSES):
        Process(target=worker, args=(task_queue, done_queue)).start()

    # Get and print results
    print 'Unordered results:'
    for i in range(len(TASKS1)):
        print '\t', done_queue.get()

    # Add more tasks using `put()` instead of `putMany()`
    for task in TASKS2:
        task_queue.put(task)

    # Get and print some more results
    for i in range(len(TASKS2)):
        print '\t', done_queue.get()

    # Tell child processes to stop
    for i in range(NUMBER_OF_PROCESSES):
        task_queue.put('STOP')
Esempio n. 2
0
def load():
	queue=Queue()
	hostfile_line=open(sys.argv[2],'r').readlines()
	source=sys.argv[3]
	destdir=sys.argv[4]
	for hostfile in hostfile_line:
		eachline=hostfile.split()
		queue.put(eachline)
		eachline=Process(target=TRANS,args=(queue.get(),source,destdir))
		eachline.start()
	eachline.join()
Esempio n. 3
0
def exe():
	queue=Queue()
	hostfile_line=open(sys.argv[2],'r').readlines()
	command_file=open(sys.argv[3],'r').readlines()
	for command_line in command_file:
		command_list=command_line.split('\n')
		command=''.join(command_list)
		for hostfile in hostfile_line:
			eachline=hostfile.split()
			queue.put(eachline)
			eachline=Process(target=SSH,args=(queue.get(),str(command)))
			eachline.start()
	eachline.join()
    while True:
        time.sleep(.1)
        if out.empty():
            sys.exit()
            print(f"Process Number: {i}")
        ipaddr = out.get()
        s = Snmp()
        h = HostRecord()
        h.ip = ipaddr
        h.snmp_response = s.query()
        print(h)
        return h


try:
    q.putmany(ips)
finally:
    for i in range(num_workers):
        p = Process(target=f, args=[i, q, oq])
        p.start()

    for i in range(num_workers):
        pp = Process(target=snmp_query, args=[i, oq])
        pp.start()

print("main process joins on queue")
p.join()
#while not oq.empty():
#
print("Validated", oq.get())
print("Main Program finished")
Esempio n. 5
0
def algo(request, algo):
    text = ""
    type = ""
    algo_object = get_object_or_404(Algo, shortTitle=algo)
    manual = get_object_or_404(ManPage, algo=algo_object)
    
    embedFormDict = { 'cpt' : CPTEmbedForm,
                   'f5' : F5EmbedForm,
                   'lsb' : LsbEmbedForm,
                   'gifshuffle' : GifShuffleEmbedForm,
                   'bs' : BattlestegEmbedForm, }
    
    extractFormDict = { 'cpt' : CPTExtractForm,
                   'f5' : F5ExtractForm,
                   'lsb' : LsbExtractForm,
                   'gifshuffle' : GifShuffleExtractForm,
                   'bs' : BattlestegExtractForm, }
    typeDict = { 'cpt' : "png",
               'f5' : "jpeg",
               'lsb' : "png",
               'gifshuffle' : "gif",
               'bs' : "png", }
    
    if request.method == 'POST':
        
        q = Queue()
        # embedding
        if "submit1" in request.POST:
            
            algoDict = { 'cpt' : cptEmbed,
                           'f5' : f5Embed,
                           'lsb' : lsbEmbed,
                           'gifshuffle' : gifShuffleEmbed,
                           'bs' : bsEmbed, }
            
            embedForm = embedFormDict[algo](request.POST, request.FILES)
            extractForm = extractFormDict[algo]()
            type = typeDict[algo]
            p = Process(target=algoDict[algo], args=(q, ))

            # fork process to embed
            if embedForm.is_valid():
                p.start()
                q.put([request.POST, request.FILES['file'].temporary_file_path()])
                os.system("sleep 1")
                try:
                    retval = q.get(True, 10)
                except Q.Empty:
                    retval = -2
                p.join()
                if retval == -1:
                    text += "%s-Datei nicht gefunden oder fehlerhaft."%(type)
                elif retval == -2:
                    text += "Fehler beim Einbetten. Anderes Bild oder andere Parameter versuchen."
                else:
                    return createResponse(retval, type)
        # extracting        
        elif "submit2" in request.POST:
             
            algoDict = { 'cpt' : cptExtract,
                           'f5' : f5Extract,
                           'lsb' : lsbExtract,
                           'gifshuffle' : gifShuffleExtract,
                           'bs' : bsExtract, }

            embedForm = embedFormDict[algo]()
            extractForm = extractFormDict[algo](request.POST, request.FILES)
            type = typeDict[algo]
            p = Process(target=algoDict[algo], args=(q, ))
            
            # fork process to extract
            if extractForm.is_valid():
                p.start()
                q.put([request.POST, request.FILES['file'].temporary_file_path()])
                try:
                    retval = q.get(True, 10)
                except Q.Empty:
                    retval = -2
                p.join()
                if retval == -1:
                    text += "%s-Datei nicht gefunden oder fehlerhaft."%(type)
                elif retval == -2:
                    text += "Fehler beim Ausbetten. Anderes Bild oder andere Parameter versuchen."
                else:
                    #print retval
                    text += retval
    # empty form
    else:
        embedForm = embedFormDict[algo]()
        extractForm = extractFormDict[algo]()
    # render
    return render_to_response("stego_algo.html", {'algo' : algo_object,
                                            'embedForm' : embedForm, 
                                            'extractForm' : extractForm,
                                            'text' : text,
                                            'algo_type' : 'Staganographie',
                                            'manual' : manual,}) 
Esempio n. 6
0
 task_id = 0
 for i in range(len(strategy_args)):
     args = strategy_args[i]
     for day in days:
         task = {'strategy_id': i, 'strategy_args': args, 
                 'day': day.timetuple()[:3], 'ticker': ticker_details, 
                 'task_id': task_id}
         tasks[task_id] = task
         task_id += 1
 
 # put the tasks in the queue
 queue.putmany(tasks.values())
 print "%s: start analyzing %s tasks" % (str(datetime.now()), len(tasks))
 
 for i in range(len(tasks)):
     result_dict = result.get()
     for task_id, report in result_dict.items():
         tsk = tasks.get(task_id)
         tsk.update({'report': report})
         print "analyzed task: %s" % task_id
     
 p1.stop(); p2.stop()
 p1.join(); p2.join()
 
 # store the pickled tasks in a file for later analysis
 fname = "../simulations/first_run_%s" % start_time.strftime("%Y%m%d%H%M%S")
 f = open(fname, 'w')
 pickle.dump(tasks, f, pickle.HIGHEST_PROTOCOL)
 f.close()
 print "output written to: %s" % fname
     
Esempio n. 7
0
        ret = subprocess.call("ping -c 1 %s" % ip,
                        shell=True,
                        stdout=open('/dev/null', 'w'),
                        stderr=subprocess.STDOUT)
        if ret == 0:
            print "%s: is alive" % ip
            out.put(ip)
        else:
            pass

def snmp(i,q=ping_out_queue,out=snmp_out_queue)
    while True:
        if q.empty()
            sys.exit()
        #print "Process Number: %s" % i
        ip = q.get()
        ret = 
for ip in ips:
    q.put(ip)

for i in range(num_ping_workers):
    p = Process(target=ping, args=[i,q])
    p.start()

for i in range(num_snmp_workers):
    p = Process(target=f, args=[i,q])
    p.start()

print "main process joins on queue"
p.join()
print "Main Program finished"