gh-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: https://github.com/sagemath/sage/pull/41227
Reported by: Lennard Hofmann
Reviewer(s): David Coudert