Coverage for sparkle/tools/general.py: 67%

6 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-27 09:10 +0000

1"""General tools for Sparkle.""" 

2import time 

3import random 

4import os 

5 

6 

7def get_time_pid_random_string() -> str: 

8 """Return a combination of time, Process ID, and random int as string. 

9 

10 Returns: 

11 A random string composed of time, PID and a random positive integer value. 

12 """ 

13 time_stamp = time.strftime("%Y-%m-%d-%H:%M:%S", time.localtime(time.time())) 

14 return f"{time_stamp}_{os.getpid()}_{int(random.getrandbits(32))}"