Browse Source

[#85496] Add spinlock and bump date

main
Przemysław Barcicki 2 months ago
parent
commit
f2b33e10d0
  1. 11
      common.py
  2. 2
      graph.py
  3. 24
      sargraph.py
  4. 4
      watch.py

11
common.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# (c) 2019-2023 Antmicro <www.antmicro.com> # (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0 # License: Apache-2.0
# #
@ -11,6 +11,7 @@ import subprocess
import sys import sys
import re import re
import platform import platform
import time
# Increase major number for general changes, middle number for smaller changes # Increase major number for general changes, middle number for smaller changes
@ -45,6 +46,14 @@ def pid_running(pid):
def file_exists(filename: str): def file_exists(filename: str):
return os.path.exists(filename) return os.path.exists(filename)
# Spin and wait until function succeeds
def spinloop(f, wait: float, tries: int):
for _ in range(tries):
if f():
return True
time.sleep(wait)
return False
# Convert a string to float, also when the separator is a comma # Convert a string to float, also when the separator is a comma
def stof(s): def stof(s):

2
graph.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# (c) 2019-2023 Antmicro <www.antmicro.com> # (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0 # License: Apache-2.0
# #

24
sargraph.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# (c) 2019-2023 Antmicro <www.antmicro.com> # (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0 # License: Apache-2.0
# #
@ -88,13 +88,9 @@ if args.command[0] == "start":
) )
# Spinloop to see whether the subprocess even starts # Spinloop to see whether the subprocess even starts
attempts = 5 if spinloop(lambda: file_exists(socket_path), 0.1, 5):
while attempts: print(f"Session '{args.session}' started")
time.sleep(0.1) sys.exit(0)
if file_exists(socket_path):
print(f"Session '{args.session}' started")
sys.exit(0)
attempts -= 1
fail("Session did not start") fail("Session did not start")
@ -108,14 +104,10 @@ elif args.command[0] == "stop":
send(args.session, f"command:q:{args.command[1]}") send(args.session, f"command:q:{args.command[1]}")
# Spinloop to see whether the subprocess even dies # Spinloop to see whether the subprocess even dies
attempts = 5 if spinloop(lambda: not file_exists(socket_path), 0.5, 5):
while attempts: print(f"Session '{args.session}' killed")
time.sleep(0.5) sys.exit(0)
if not file_exists(socket_path):
print(f"Session '{args.session}' killed")
sys.exit(0)
attempts -= 1
fail("Session did not respond") fail("Session did not respond")

4
watch.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# #
# (c) 2019-2023 Antmicro <www.antmicro.com> # (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0 # License: Apache-2.0
# #
@ -131,7 +131,7 @@ class Watcher(abc.ABC):
self.socket, self.socket_path = get_socket(self.session) self.socket, self.socket_path = get_socket(self.session)
# Was a graph alreay produced by save command from sargraph? # Was a graph already produced by save command from sargraph?
self.dont_plot = False self.dont_plot = False
# Should we die? # Should we die?

Loading…
Cancel
Save