`automata('command |')` should kill the command when the generator is destroyed
Consider
import spot
from gc import collect
from subprocess import run
def two_intersecting_automata():
"""return two random automata with a non-empty intersection"""
g = spot.automata('randaut -A4 -Q5 -n-1 2 |')
for a, b in zip(g, g):
if a.intersects(b):
return a, b
a1, b1 = two_intersecting_automata()
a2, b2 = two_intersecting_automata()
a3, b3 = two_intersecting_automata()
a4, b4 = two_intersecting_automata()
collect()
run('ps aux | grep randaut', shell=True)
This displays
0.0 4396 752 ? Ss 12:00 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16300 0.0 0.1 32820 15440 ? S 12:00 0:00 randaut -A4 -Q5 -n-1 2
adl 16301 0.0 0.0 4396 796 ? Ss 12:00 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16302 0.0 0.1 32820 15908 ? S 12:00 0:00 randaut -A4 -Q5 -n-1 2
adl 16303 0.0 0.0 4396 808 ? Ss 12:00 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16304 0.0 0.1 32820 16024 ? S 12:00 0:00 randaut -A4 -Q5 -n-1 2
adl 16554 0.0 0.0 4396 800 ? Ss 13:34 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16555 0.0 0.1 32820 15468 ? S 13:34 0:00 randaut -A4 -Q5 -n-1 2
adl 16556 0.0 0.0 4396 904 ? Ss 13:34 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16557 0.0 0.1 32820 15536 ? S 13:34 0:00 randaut -A4 -Q5 -n-1 2
adl 16558 0.0 0.0 4396 904 ? Ss 13:34 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16559 0.0 0.1 32820 15452 ? S 13:34 0:00 randaut -A4 -Q5 -n-1 2
adl 16560 0.0 0.0 4396 800 ? Ss 13:34 0:00 /bin/sh -c randaut -A4 -Q5 -n-1 2
adl 16561 0.0 0.1 32820 15116 ? S 13:34 0:00 randaut -A4 -Q5 -n-1 2
adl 16562 0.0 0.0 4396 804 pts/1 S+ 13:34 0:00 /bin/sh -c ps aux | grep randaut
adl 16564 0.0 0.0 12904 1076 pts/1 S+ 13:34 0:00 grep randaut
In other words, the randaut
process are not killed when the generator created by spot.automata()
is destroyed.