Report elapsed time
This commit is contained in:
		
							parent
							
								
									d77b88ef9f
								
							
						
					
					
						commit
						a653a90ad1
					
				|  | @ -3,6 +3,7 @@ from functools import partial | |||
| from itertools import product | ||||
| from multiprocessing import Pool | ||||
| from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired | ||||
| from time import time | ||||
| from typing import List | ||||
| 
 | ||||
| chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ' | ||||
|  | @ -106,9 +107,8 @@ def find_script( | |||
|     :returns: list of matching scripts | ||||
|     """ | ||||
|     candidates = [] | ||||
|     bound_check_script = partial(check_script, pairs, timeout) | ||||
| 
 | ||||
|     out_invalid = [] | ||||
|     bound_check_script = partial(check_script, pairs, timeout) | ||||
| 
 | ||||
|     for i in range(max_length + 1): | ||||
|         out_invalid.append(open(invalid_prefix + str(i), "w")) | ||||
|  | @ -116,6 +116,7 @@ def find_script( | |||
|     chars_count = len(chars) | ||||
|     num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1)) | ||||
|     done_tasks = 0 | ||||
|     start_time = time() | ||||
| 
 | ||||
|     with Pool(processes) as pool: | ||||
|         for script, status in pool.imap_unordered( | ||||
|  | @ -128,7 +129,8 @@ def find_script( | |||
|             if done_tasks % 10000 == 0: | ||||
|                 print( | ||||
|                     f"Progress: {done_tasks}/{num_tasks} \ | ||||
| {done_tasks / num_tasks * 100:.1f}%", | ||||
| {done_tasks / num_tasks * 100:.1f}% \ | ||||
| (running for {time() - start_time:.1f}s)", | ||||
|                     file=out_log, flush=True | ||||
|                 ) | ||||
| 
 | ||||
|  | @ -145,4 +147,5 @@ def find_script( | |||
|     for file in out_invalid: | ||||
|         file.close() | ||||
| 
 | ||||
|     print(f"Finished in {time() - start_time:.1f}s", file=out_log, flush=True) | ||||
|     return candidates | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue