[Tilesathome] Signal handler for tilesgen in loop mode
Scott Walde
scott at waldetech.ca
Sat May 26 18:29:10 BST 2007
Nevermind... it doesn't work.
We have to make the programs that tilesgen calls ignore ctrl-c for this
to work properly.
ttyl
srw
Scott Walde wrote:
> This patch adds a signal handler to tilesGen.pl that gets enabled in
> loop mode. It traps SIGINT (ctrl-c) and increments a counter. The
> loop mode "while" loop is changed to read while($sigintcount==0)
> instead of while(1). The handler will exit immediately when
> $sigintcount == 3. The end result:
>
> In loop mode, a single Ctrl-C will cause tilesGen.pl to finish the
> current tileset, then exit. Three ctrl-cs will exit the program now
> with no cleanup instead of finishing.
>
> This is a scratch I've been meaning to itch for a while, but only got
> around to it today. I hope you find it useful.
>
> Legalese: This patch is licensed with the same license as tilesGen.pl.
>
> ttyl
> srw
>
>
> ------------------------------------------------------------------------
>
> Index: tilesGen.pl
> ===================================================================
> --- tilesGen.pl (revision 3033)
> +++ tilesGen.pl (working copy)
> @@ -47,6 +47,30 @@
> exit(3);
> }
>
> +#
> +# SIGINT will gracefully exit 'loop' mode after the current tileset is done
> +# three SIGINTs will exit now.
> +#
> +# The handler is here, but is only enabled in loop mode.
> +#
> +my $sigintcount=0;
> +sub catch_sigint {
> + $sigintcount++;
> + if($sigintcount == 1)
> + {
> + print STDERR "\nSIGINT recieved. We will exit gracefully after this tileset\n";
> + }
> + elsif($sigintcount == 2)
> + {
> + print STDERR "\nPress Ctrl-C once more to exit NOW\n";
> + }
> + else
> + {
> + print STDERR "\nExiting without cleaning up!\n";
> + exit(1);
> + }
> +}
> +
> # Setup GD options
> # currently unused (GD 2 truecolor mode)
> #
> @@ -115,6 +139,9 @@
> # Continuously process requests from server
> # ----------------------------------
>
> + # Set the signal handler for Ctrl-C (SIGINT) here.
> + $SIG{INT} = \&catch_sigint;
> +
> # if this is a re-exec, we want to capture some of our status
> # information from the command line. this feature allows setting
> # any numeric variable by specifying "variablename=value" on the
> @@ -136,14 +163,14 @@
>
> # this is the actual processing loop
>
> - while(1)
> + while($sigintcount==0)
> {
> reExecIfRequired();
> my ($did_something, $message) = ProcessRequestsFromServer();
> uploadIfEnoughTiles();
> if ($did_something == 0)
> {
> - talkInSleep($message, 60);
> + talkInSleep($message, 60) unless $sigintcount;
> }
> else
> {
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tilesathome mailing list
> Tilesathome at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/tilesathome
>
More information about the Tilesathome
mailing list