Skip to content

Commit

Permalink
ros2cli.node.daemon : try getting fdsize from /proc for open fd limit (
Browse files Browse the repository at this point in the history
…#888)

* ros2cli.node.daemon : try getting fdsize from /proc for open fd limit

* - add with-block; remove linux check

* - use removeprefix

* - replace filter with loop

Signed-off-by: akssri <[email protected]>
  • Loading branch information
akssri-sony authored Mar 9, 2024
1 parent b16fb02 commit 64d216c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions ros2cli/ros2cli/node/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,22 @@ def spawn_daemon(args, timeout=None, debug=False):
# for 0, 1, 2, and the server socket as non-inheritable, which will cause daemonize() to close
# those file descriptors. See https://github.com/ros2/ros2cli/issues/851 for more details.
if platform.system() != 'Windows':
import resource
soft, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
for i in range(3, soft):
# Some unices have a high soft_limit; read fdsize if available.
fdlimit = None
try:
string_to_find = 'FDSize:'
with open('/proc/self/status', 'r') as f:
for line in f:
if line.startswith(string_to_find):
fdlimit = int(line.removeprefix(string_to_find).strip())
break
except (FileNotFoundError, ValueError):
pass
# The soft limit might be quite high on some systems.
if fdlimit is None:
import resource
fdlimit, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
for i in range(3, fdlimit):
try:
if i != server.socket.fileno() and os.get_inheritable(i):
os.set_inheritable(i, False)
Expand Down

0 comments on commit 64d216c

Please sign in to comment.