The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
GaudiMP.FdsRegistry.FdsDict Class Reference
Inheritance diagram for GaudiMP.FdsRegistry.FdsDict:
Collaboration diagram for GaudiMP.FdsRegistry.FdsDict:

Public Member Functions

 __missing__ (self, key)
 fname (self, i)
 fds (self, fname)
 has_name (self, fname)
 add (self, i, fname, iomode, flags)
 iomode (self, i)
 get_output_fds (self)
 get_input_fds (self)
 get_fds_in_dir (self, dir="")
 create_symlinks (self, wkdir="")
 extract_fds (self, dir="")

Static Public Attributes

str name = "fds_dict"
 curdir = None

Detailed Description

Definition at line 22 of file FdsRegistry.py.

Member Function Documentation

◆ __missing__()

GaudiMP.FdsRegistry.FdsDict.__missing__ ( self,
key )

Definition at line 26 of file FdsRegistry.py.

26 def __missing__(self, key):
27 self[key] = ""
28 return ""
29

◆ add()

GaudiMP.FdsRegistry.FdsDict.add ( self,
i,
fname,
iomode,
flags )

Definition at line 47 of file FdsRegistry.py.

47 def add(self, i, fname, iomode, flags):
48 self[i] = (fname, iomode, flags)
49 return
50

◆ create_symlinks()

GaudiMP.FdsRegistry.FdsDict.create_symlinks ( self,
wkdir = "" )
create necessary symlinks in worker's dir if the fd is <INPUT>
otherwise copy <OUTPUT> file

Definition at line 74 of file FdsRegistry.py.

74 def create_symlinks(self, wkdir=""):
75 """
76 create necessary symlinks in worker's dir if the fd is <INPUT>
77 otherwise copy <OUTPUT> file
78 """
79 import os
80 import shutil
81
82 msg.info(f"create_symlinks: {self.get_fds_in_dir()}")
83 # some files expected to be in curdir
84 for fd in self.get_fds_in_dir():
85 src = self[fd][0]
86 iomode = self[fd][1]
87 dst = os.path.join(wkdir, os.path.basename(src))
88 if iomode == "<INPUT>":
89 if os.path.exists(dst):
90 # update_io_registry took care of this
91 msg.debug(
92 f"fds_dict.create_symlink:update_io_registry took care of src={src}"
93 )
94 pass
95 else:
96 msg.debug(
97 f"fds_dict.create_symlink:(symlink) src={src}, iomode={iomode}"
98 )
99 os.symlink(src, dst)
100 else:
101 msg.debug(f"fds_dict.create_symlink: (copy) src={src}, dst={dst}")
102 shutil.copy(src, dst)
103 pass
104 return
105

◆ extract_fds()

GaudiMP.FdsRegistry.FdsDict.extract_fds ( self,
dir = "" )
parse the fds of the processs -> build fds_dict

Definition at line 106 of file FdsRegistry.py.

106 def extract_fds(self, dir=""):
107 """parse the fds of the processs -> build fds_dict"""
108 import fcntl
109 import os
110
111 msg.info("extract_fds: making snapshot of parent process file descriptors")
112 self.curdir = os.path.abspath(os.curdir)
113 iomode = "<INPUT>"
114
115 procfd = "/proc/self/fd"
116 fds = os.listdir(procfd)
117 for i in fds:
118 fd = int(i) # spurious entries should raise at this point
119 if fd == 1 or fd == 2:
120 # leave stdout and stderr to redirect_log
121 continue
122 elif fd == 0:
123 # with only a single controlling terminal, leave stdin alone
124 continue
125
126 try:
127 realname = os.path.realpath(os.path.join(procfd, i))
128 except (OSError, TypeError):
129 # can fail because the symlink resolution (why is that needed
130 # anyway?) may follow while a temp file disappears
131 msg.debug("failed to resolve: %s ... skipping", os.path.join(procfd, i))
132 continue
133
134 if os.path.exists(realname):
135 try:
136 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
137 if (flags & _O_ACCMODE) == 0: # read-only --> <INPUT>
138 iomode = "<INPUT>"
139 else:
140 iomode = "<OUTPUT>"
141
142 self.add(fd, realname, iomode, flags)
143 except OSError:
144 # likely saw a temoorary file; for now log a debug
145 # message, but this is fine if silently ignored
146 msg.debug("failed access to: %s ... skipping", realname)
147 continue
148
149 # at this point the list of fds may still include temp files
150 # TODO: figure out if they can be identified (seeing /tmp is
151 # not enough as folks like to run with data from /tmp b/c of
152 # space constraints on /afs
153
154 msg.debug(f"extract_fds.fds_dict={self}")
155 return
156

◆ fds()

GaudiMP.FdsRegistry.FdsDict.fds ( self,
fname )

Definition at line 37 of file FdsRegistry.py.

37 def fds(self, fname):
38 return [i for i, v in self.iteritems() if v[0] == fname]
39

◆ fname()

GaudiMP.FdsRegistry.FdsDict.fname ( self,
i )

Definition at line 30 of file FdsRegistry.py.

30 def fname(self, i):
31 if i in self:
32 return self[i][0]
33 else:
34 msg.warning(f"fds_dict:fname: No Key {i}")
35 return ""
36

◆ get_fds_in_dir()

GaudiMP.FdsRegistry.FdsDict.get_fds_in_dir ( self,
dir = "" )

Definition at line 64 of file FdsRegistry.py.

64 def get_fds_in_dir(self, dir=""):
65 import os
66
67 if dir == "" and self.curdir is not None:
68 dir = self.curdir
69 msg.debug(f"get_fds_in_dir({dir})")
70 return [
71 i for i in self.keys() if os.path.samefile(os.path.dirname(self[i][0]), dir)
72 ]
73

◆ get_input_fds()

GaudiMP.FdsRegistry.FdsDict.get_input_fds ( self)

Definition at line 61 of file FdsRegistry.py.

61 def get_input_fds(self):
62 return [i for i in self.keys() if self[i][1] == "<INPUT>"]
63

◆ get_output_fds()

GaudiMP.FdsRegistry.FdsDict.get_output_fds ( self)

Definition at line 58 of file FdsRegistry.py.

58 def get_output_fds(self):
59 return [i for i in self.keys() if self[i][1] == "<OUTPUT>"]
60

◆ has_name()

GaudiMP.FdsRegistry.FdsDict.has_name ( self,
fname )

Definition at line 40 of file FdsRegistry.py.

40 def has_name(self, fname):
41 for v in self.values():
42 if v[0] == fname:
43 return True
44 return False
45

◆ iomode()

GaudiMP.FdsRegistry.FdsDict.iomode ( self,
i )

Definition at line 51 of file FdsRegistry.py.

51 def iomode(self, i):
52 if i in self:
53 return self[i][1]
54 else:
55 msg.warning(f"fds_dict:iomode: No Key {i}")
56 return ""
57

Member Data Documentation

◆ curdir

GaudiMP.FdsRegistry.FdsDict.curdir = None
static

Definition at line 24 of file FdsRegistry.py.

◆ name

str GaudiMP.FdsRegistry.FdsDict.name = "fds_dict"
static

Definition at line 23 of file FdsRegistry.py.


The documentation for this class was generated from the following file: