MCPcopy
hub / github.com/celery/celery / fd_by_path

Function fd_by_path

celery/platforms.py:275–307  ·  view source on GitHub ↗

Return a list of file descriptors. This method returns list of file descriptors corresponding to file paths passed in paths variable. Arguments: paths: List[str]: List of file paths. Returns: List[int]: List of file descriptors. Example: >>> keep = fd_

(paths)

Source from the content-addressed store, hash-verified

273
274
275def fd_by_path(paths):
276 """Return a list of file descriptors.
277
278 This method returns list of file descriptors corresponding to
279 file paths passed in paths variable.
280
281 Arguments:
282 paths: List[str]: List of file paths.
283
284 Returns:
285 List[int]: List of file descriptors.
286
287 Example:
288 >>> keep = fd_by_path(['/dev/urandom', '/my/precious/'])
289 """
290 stats = set()
291 for path in paths:
292 try:
293 fd = os.open(path, os.O_RDONLY)
294 except OSError:
295 continue
296 try:
297 stats.add(os.fstat(fd)[1:3])
298 finally:
299 os.close(fd)
300
301 def fd_in_stats(fd):
302 try:
303 return os.fstat(fd)[1:3] in stats
304 except OSError:
305 return False
306
307 return [_fd for _fd in range(get_fdmax(2048)) if fd_in_stats(_fd)]
308
309
310class DaemonContext:

Callers 2

test_fd_by_pathFunction · 0.90
openMethod · 0.85

Calls 4

fd_in_statsFunction · 0.85
openMethod · 0.45
addMethod · 0.45
closeMethod · 0.45

Tested by 1

test_fd_by_pathFunction · 0.72