diff --git a/CHANGES b/CHANGES index 1233102..1e4983c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +- when process ends with die or SIGINT, close all non-"persist" windows + 2.030 2024-09-29 - require PDL version that has raster2fits; previously didn't require one with t_raster2fits which test used diff --git a/lib/PDL/Graphics/Gnuplot.pm b/lib/PDL/Graphics/Gnuplot.pm index b88c092..4f69047 100644 --- a/lib/PDL/Graphics/Gnuplot.pm +++ b/lib/PDL/Graphics/Gnuplot.pm @@ -67,7 +67,6 @@ # each option. Since this mechanism is near at hand, we use it even # for routines (such as read_polygon) that could and would use # PDL::Options in other circumstances. -# =encoding UTF-8 @@ -2076,6 +2075,14 @@ our @EXPORT_OK = qw( ); our @EXPORT = qw(gpwin gplot greplot greset grestart); +use Scalar::Util qw(refaddr weaken); +my %OBJECTS_TO_CLEANUP; +$SIG{TERM} = $SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { die; }; +END { +eval {$_->close} for grep defined && !$_->{persist}, + values %OBJECTS_TO_CLEANUP; +} + # when testing plots with binary i/o, this is the unit of test data my $testdataunit_binary = "........"; # 8 bytes - length of an IEEE double @@ -2392,13 +2399,13 @@ FOO # Default the 'persist' option to 0, so that interactive windows behave nicely unless # asked to stay. - if(exists($termTab->{$terminal}->{opt}->[0]->{persist}) and + if (exists($termTab->{$terminal}{opt}[0]{persist}) and !defined($termOptions->{persist}) ) { $termOptions->{persist} = 0; } # Default the 'dashed' option to 1. - if(exists($termTab->{$terminal}->{opt}->[0]->{dashed}) and + if (exists($termTab->{$terminal}{opt}[0]{dashed}) and !defined($termOptions->{dashed}) ) { $termOptions->{dashed} = 1; } @@ -2452,9 +2459,9 @@ sub DESTROY { my $this = shift; _killGnuplot($this); + delete $OBJECTS_TO_CLEANUP{refaddr $this}; } - =pod =head2 close @@ -7242,6 +7249,7 @@ EOM _checkpoint($this, "main"); + $OBJECTS_TO_CLEANUP{refaddr $this} = weaken(my $weakref = $this); $this; }