Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Wrapper script to get the Redis broker URL from condor and launch another tool. 

3 

4In a job running under HTCondor, the environment variable `_CONDOR_MACHINE_AD` 

5is the path of a text file that contains the machine's ClassAd attributes. The 

6`ClientMachine` attribute records the hostname of the machine that has claimed 

7the machine on which the job is running, i.e., the submit machine. We assume 

8that the Redis server is running on the submit machine. 

9""" 

10import os 

11import re 

12import sys 

13 

14 

15def get_classad_attribute(filename, attrib): 

16 pattern = r'^' + re.escape(attrib) + r'\s*=\s*"(.*)"\s*$' 

17 regex = re.compile(pattern) 

18 with open(filename, 'r') as f: 

19 for line in f: 

20 match = regex.match(line) 

21 if match is not None: 

22 return match.group(1) 

23 raise ValueError( 

24 f'ClassAd attribute "{attrib}" not found in file "{filename}"') 

25 

26 

27def main(): 

28 filename = os.environ['_CONDOR_MACHINE_AD'] 

29 hostname = get_classad_attribute(filename, 'ClientMachine') 

30 os.environ['CELERY_BROKER_URL'] = f'redis://{hostname}' 

31 os.execvp(sys.argv[1], sys.argv[1:])