Project

General

Profile

Bug #10009 » teste_thread_schedule.py

ariveira (Alexandre Riveira), 07/08/2014 09:54 AM

 
import thread
import time
import sys

inicio_geral = time.time()

result = {"1": 0, "2": 0, "3": 0}

def looping(key):
while True:
result[key] += 1

thread.start_new_thread( looping, ("1", ) )

count = 0
while count < 10:
inicio = time.time()
count += 1
time.sleep(1)
print 'faltando ' + str(count) + ' segundos (' + str(time.time() - inicio) + ')'


print "zerando thread com contagem em " + str(result['1'])
result['1'] = 0
thread.start_new_thread( looping, ("2", ) )
thread.start_new_thread( looping, ("3", ) )

totalizador = 0
while totalizador < 10:
print "primeira " + str(result['1'])
print "segunda " + str(result['2'])
print "terceira " + str(result['3'])
print "\n\n"
totalizador += 1
time.sleep(1)

total = result['1'] + result['2'] + result['3']
print "total " + str(total)
print "media " + str(total/(time.time() - inicio_geral))
say = 'Python Elapsed %.02f' % (time.time() - inicio_geral)
print say
sys.exit()

(2-2/8)