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
#
# (c) 2019-2023 Antmicro <www.antmicro.com>
# (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0
#
@ -11,6 +11,7 @@ import subprocess
import sys
import re
import platform
import time
# Increase major number for general changes, middle number for smaller changes
@ -45,6 +46,14 @@ def pid_running(pid):
def file_exists(filename: str):
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
def stof(s):

2
graph.py

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

24
sargraph.py

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

4
watch.py

@ -1,7 +1,7 @@
#!/usr/bin/env python3
#
# (c) 2019-2023 Antmicro <www.antmicro.com>
# (c) 2019-2026 Antmicro <www.antmicro.com>
# License: Apache-2.0
#
@ -131,7 +131,7 @@ class Watcher(abc.ABC):
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
# Should we die?

Loading…
Cancel
Save