3 # © Copyright 2021-2023, Scott Gasch
5 """Miscellaneous utilities."""
12 def is_running_as_root() -> bool:
15 True if running as root, False otherwise.
17 >>> is_running_as_root()
20 return os.geteuid() == 0
23 def debugger_is_attached() -> bool:
26 True if a debugger is attached, False otherwise.
28 gettrace = getattr(sys, "gettrace", lambda: None)
29 return gettrace() is not None
32 def execute_probabilistically(probability_to_execute: float) -> bool:
35 probability_to_execute: the probability of returning True.
38 True with a given probability.
41 >>> execute_probabilistically(50.0)
43 >>> execute_probabilistically(50.0)
47 return random.uniform(0.0, 100.0) < probability_to_execute
50 if __name__ == "__main__":