Exemplo n.º 1
0
# from utils.PackageManager import PackageManager
# PackageManager.importPackage("pyximport","cython") #Import the package pyximport that's installed with Cython
# pyximport.install(pyimport=True, inplace=True, build_in_temp=False) #There's now in the global space, i await
import random, time, traceback, logging, Queue, os, inspect, threading
# logging.basicConfig(level=logging.INFO)
from utils.MicroThread import MicroThread, MicroThreadPoll, microThreadDecorator, OrderedPrint
try: 
    import cython
except ImportError:
    cython = None
num_thread = raw_input("Informe quantas threads devem ser usadas para execucao do teste (padrao = Numero de cores do seu PC)")
if not num_thread.isdigit():
    num_thread = True
else:
    num_thread = int(num_thread)
MicroThreadPoll.getInstance(num_thread)
MicroThreadPoll.startAll()
# def soma():
#    n1 = (yield "Numero 1")
#    n2 = (yield "Numero 2")
#    yield "O resultado da soma eh %d"%(n1+n2)
# def callback(thread, mode, result=None):
#    if mode == "yield":
#        if thread.isWaiting():
#            thread.send(int(raw_input(result)))
#        else:
#            print result
# print MicroThreadPoll.parse(soma)
# print MicroThreadPoll.parse(callback)
# t = MicroThread(soma)
# t.addCallback(callback)
Exemplo n.º 2
0
'''
Created on 19/01/2013

@author: fernando
'''
import sys, os, time
sys.path.insert(0, os.path.realpath(os.path.join(os.getcwd(), "..", "..")))
from utils.MicroThread import MicroThread, MicroThreadPoll
MicroThreadPoll.getInstance(True)
print "Iniciando instancias.."
MicroThreadPoll.startAll()
def justSleep():
    print "Dormindo.."
    time.sleep(5)
    print "Terminou de dormir..xD"

microthreads = []
for _ in xrange(100):
    print "Criando micro-thread.."
    microthread = MicroThread(justSleep)
    print "Iniciando micro-thread.."
    microthread.start()  # Put in the queue!
    microthread.setTimeout(5.1)
    print "Adicionando a lista.."
    microthreads.append(microthread)

for microthread in microthreads:
    print "Aguardando.."
    microthread.join()
    print "Terminou de aguardar.."