Debian Codegraph @

test/integration/targets/throttle/test_throttle.py

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2
3 from __future__ import annotations
4
5 import os
6 import sys
7 import time
8
9 # read the args from sys.argv
10 throttledir, inventory_hostname, max_throttle = sys.argv[1:]
11 # format/create additional vars
12 max_throttle = int(max_throttle)
13 throttledir = os.path.expanduser(throttledir)
14 throttlefile = os.path.join(throttledir, inventory_hostname)
15 try:
16 # create the file
17 with open(throttlefile, 'a'):
18 os.utime(throttlefile, None)
19 # count the number of files in the dir
20 throttlelist = os.listdir(throttledir)
21 print("tasks: %d/%d" % (len(throttlelist), max_throttle))
22 # if we have too many files, fail
23 if len(throttlelist) > max_throttle:
24 print(throttlelist)
25 raise ValueError("Too many concurrent tasks: %d/%d" % (len(throttlelist), max_throttle))
26 time.sleep(1.5)
27 finally:
28 # remove the file, then wait to make sure it's gone
29 os.unlink(throttlefile)
30 while True:
31 if not os.path.exists(throttlefile):
32 break
33 time.sleep(0.1)