Project

General

Profile

Bug #10009 » test.py

ariveira (Alexandre Riveira), 10/29/2014 01:23 PM

 
import thread
import time
import sys
import psycopg2

postgres = False
if len(sys.argv) > 1 and sys.argv[1] == '--postgres':
postgres = True


inicio_geral = time.time()

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

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

def database(key):
conn = psycopg2.connect("\
dbname='postgres'\
user='postgres'\
host='localhost'\
password='abc123'\
");
while True:
c = conn.cursor()
c.execute("SELECT * FROM pg_stat_activity")
records = c.fetchall()
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

if postgres:
label = "postgres "
thread.start_new_thread( database, ("2", ) )
else:
label = "second "
thread.start_new_thread( looping, ("2", ) )

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

totalizador = 0
while totalizador < 10:
print("first " + str(result['1']))
print(label + str(result['2']))
print("third " + 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()
(8-8/8)