Skip to content

Conversation

@Ordoviz
Copy link
Contributor

@Ordoviz Ordoviz commented Nov 24, 2025

This fixes a "Too many open files" error when running

import resource
max_open_files = 20
resource.setrlimit(resource.RLIMIT_NOFILE,(max_open_files,max_open_files))

for _ in range(max_open_files):
    for G in graphs.nauty_geng("9"):
        break

The above relies on the fact that geng 9 takes a while to finish. While the first geng 9 process is still running, up to 20 other processes are started until the operating system runs out of file descriptors. This pull request fixes this by making sure a process is terminated when it's no longer needed.

I did not (and do not plan to) add any tests for this.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement.
In digraph_generators.py, there is also method nauty_directg.

This fixes a "Too many open files" error when running

import resource
max_open_files = 20
resource.setrlimit(resource.RLIMIT_NOFILE,(max_open_files,max_open_files))
for _ in range(max_open_files):
    for G in graphs.nauty_geng("9"):
        break
@Ordoviz Ordoviz force-pushed the fix-too-many-open-files branch from f0b0dc3 to 543dbd6 Compare November 24, 2025 19:09
@Ordoviz
Copy link
Contributor Author

Ordoviz commented Nov 24, 2025

I added a context manager for the nauty_directg subprocess.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 26, 2025
sagemathgh-41227: Fix external graph generators leaking file descriptors
    
This fixes a "Too many open files" error when running

```sage
import resource
max_open_files = 20
resource.setrlimit(resource.RLIMIT_NOFILE,(max_open_files,max_open_files
))

for _ in range(max_open_files):
    for G in graphs.nauty_geng("9"):
        break
```

The above relies on the fact that `geng 9` takes a while to finish.
While the first `geng 9` process is still running, up to 20 other
processes are started until the operating system runs out of file
descriptors. This pull request fixes this by making sure a process is
terminated when it's no longer needed.

I did not (and do not plan to) add any tests for this.
    
URL: sagemath#41227
Reported by: Lennard Hofmann
Reviewer(s): David Coudert
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 1, 2025
sagemathgh-41227: Fix external graph generators leaking file descriptors
    
This fixes a "Too many open files" error when running

```sage
import resource
max_open_files = 20
resource.setrlimit(resource.RLIMIT_NOFILE,(max_open_files,max_open_files
))

for _ in range(max_open_files):
    for G in graphs.nauty_geng("9"):
        break
```

The above relies on the fact that `geng 9` takes a while to finish.
While the first `geng 9` process is still running, up to 20 other
processes are started until the operating system runs out of file
descriptors. This pull request fixes this by making sure a process is
terminated when it's no longer needed.

I did not (and do not plan to) add any tests for this.
    
URL: sagemath#41227
Reported by: Lennard Hofmann
Reviewer(s): David Coudert
@vbraun vbraun merged commit 4acc9c7 into sagemath:develop Dec 2, 2025
20 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants