コード例 #1
0
ファイル: cansina.py プロジェクト: KxCode/cansina
thread_pool = []
for visitor_id in range(0, threads):
    v = Visitor(visitor_id, payload_queue, manager)
    thread_pool.append(v)
    v.daemon = True
    v.start()

#
#   Run the main thread until manager exhaust all tasks
#
time_before_running = time.time()
Console.header()

while True:
    try:
        if not manager.get_a_task() and any([visitor.is_alive() for visitor in thread_pool]):
            print("Finishing...")
            break
    except KeyboardInterrupt:
        print (os.linesep + "Waiting for threads to stop...")
        Visitor.kill()
        break

time_after_running = time.time()
delta = round(timedelta(seconds=(time_after_running - time_before_running)).total_seconds(), 2)
print("Task took %i seconds" % delta)

sys.stdout.write("\x1b[0K")
sys.stdout.flush()
sys.exit()
コード例 #2
0
thread_pool = []
for visitor_id in range(0, threads):
    v = Visitor(visitor_id, payload_queue, manager)
    thread_pool.append(v)
    v.daemon = True
    v.start()

#
#   Run the main thread until manager exhaust all tasks
#
time_before_running = time.time()
Console.header()

while True:
    try:
        if not manager.get_a_task() and any([visitor.is_alive() for visitor in thread_pool]):
            print("Finishing...")
            break
    except KeyboardInterrupt:
        print (os.linesep + "Waiting for threads to stop...")
        Visitor.kill()
        break

time_after_running = time.time()
delta = round(timedelta(seconds=(time_after_running - time_before_running)).total_seconds(), 2)
print("Task took %i seconds" % delta)

if not os.name == 'nt':
	sys.stdout.write("\x1b[0K")
sys.stdout.flush()
sys.exit()
コード例 #3
0
ファイル: cansina.py プロジェクト: Expertasif/cansina
    v = Visitor(visitor_id, payload_queue, manager)
    thread_pool.append(v)
    v.daemon = True
    v.start()

#
#   Run the main thread until manager exhaust all tasks
#
time_before_running = time.time()
Console.start_eta_queue(30, total_requests)
Console.header()

try:
    while True:
        visitors_alive = any([visitor.is_alive() for visitor in thread_pool])
        if not manager.get_a_task(visitors_alive):
            break
except KeyboardInterrupt:
    sys.stdout.write(os.linesep + "Waiting for threads to stop...")
    Visitor.kill()
    resp = raw_input(os.linesep + "Keep a resume file? [y/N] ")
    if resp == 'y':
        resumer.set_line(payload_queue.get().get_number())
        with open("resume_file_" + time.strftime("%d_%m_%y_%H_%M", time.localtime()), 'w') as f:
            pickle.dump(resumer, f)
except Exception as e:
    import traceback as tb
    sys.stderr.write("Unknown exception: %s" % e)
    print(tb.print_tb(sys.exc_info()[2]))

sys.stdout.write("Finishing...")
コード例 #4
0
ファイル: cansina.py プロジェクト: ver007/cansina
thread_pool = []
for visitor_id in range(0, threads):
    v = Visitor(visitor_id, payload_queue, manager)
    thread_pool.append(v)
    v.daemon = True
    v.start()

#
#   Run the main thread until manager exhaust all tasks
#
time_before_running = time.time()
Console.header()

while True:
    try:
        if not manager.get_a_task() and any(
            [visitor.is_alive() for visitor in thread_pool]):
            print("Finishing...")
            break
    except KeyboardInterrupt:
        print(os.linesep + "Waiting for threads to stop...")
        Visitor.kill()
        break

time_after_running = time.time()
delta = round(
    timedelta(seconds=(time_after_running -
                       time_before_running)).total_seconds(), 2)
print("Task took %i seconds" % delta)

sys.stdout.write("\x1b[0K")