Skip to content

Commit

Permalink
when process ends with die or SIGINT, close all non-"persist" windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 1, 2024
1 parent 4f8a063 commit 7b396a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 12 additions & 4 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -2452,9 +2459,9 @@ sub DESTROY
{
my $this = shift;
_killGnuplot($this);
delete $OBJECTS_TO_CLEANUP{refaddr $this};
}


=pod
=head2 close
Expand Down Expand Up @@ -7242,6 +7249,7 @@ EOM

_checkpoint($this, "main");

$OBJECTS_TO_CLEANUP{refaddr $this} = weaken(my $weakref = $this);
$this;
}

Expand Down

0 comments on commit 7b396a3

Please sign in to comment.