summaryrefslogtreecommitdiffstats
path: root/tclsignal/tests/test_sig_async.tk
blob: 24ac5434982bd4e2c44f531d2393e42d5b47cbe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/local/bin/wish4.1
# ENSURE YOUR TCLLIBPATH includes /usr/local/lib/signal!
# (or uncomment the appropriate load line and comment the package line)
# --SUN
# load /usr/local/lib/signal_ext.so
# --HP
# load /usr/local/lib/signal_ext.sl

# Proc to do something absurd for a long time
proc do_long_job { } { 
  for { set i 0 } { $i < 300000 } { incr i } { expr $i * $i }
}

package require Signal

signal add 21 { wm iconify . ; wm deiconify . }
signal add SIGHUP { puts "Signal 1 received" }
signal add SIGINT { puts "SIGINT received" ; error "SIGINT interrupt" } -async
signal add SIGQUIT { puts "SIGQUIT received" } -async

puts "Showing all the signals handled"
puts [signal print]
puts "Showing how 3 is handled"
puts [signal print 3]
puts "Showing how SIGTTOU is handled"
puts [signal print SIGTTOU]

frame .bottom
button .bottom.b -text "Done" -command "exit 0"
button .bottom.j -text "Long Job" -command do_long_job
button .bottom.i -text "Iconify" -command "wm iconify ."
label  .l -wraplength 60m -justify l -text {
Sending this process SIGHUP will (eventually) result in a message;

SIGQUIT (^\) will result in a message immediately.

SIGINT (^C) will result in an error trace immediately.  This is the result of the -async option on signal handlers

Signal 21 (URG) will pop the dialog up!

Pressing the "Long Job" button will perform a single, long calculation where no buttons presses will have immediate effect, but SIGINT will interrupt the calculation prematurely
}

pack .bottom.b -side left -fill x
pack .bottom.j -side left -fill x
pack .bottom.i -side right -fill x
pack .l -side top -fill both -expand true
pack .bottom -in . -side bottom -fill x

update