teste_thread_schedule.py

Alexandre Riveira, 07/08/2014 09:54 AM

Download (953 Bytes)

 
1
import thread
2
import time
3
import sys
4

    
5
inicio_geral = time.time()
6

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

    
9
def looping(key):
10
  while True:
11
    result[key] += 1
12

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

    
15
count = 0
16
while count < 10:
17
  inicio = time.time()  
18
  count += 1
19
  time.sleep(1)
20
  print 'faltando ' + str(count) + ' segundos (' + str(time.time() - inicio) + ')'
21

    
22

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

    
28
totalizador = 0
29
while totalizador < 10:
30
  print "primeira " + str(result['1'])
31
  print "segunda " + str(result['2'])
32
  print "terceira " + str(result['3'])
33
  print "\n\n"
34
  totalizador += 1
35
  time.sleep(1)
36

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