Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion How to interrupt a task which is running in a thread?

Received: by 10.66.84.38 with SMTP id v6mr2192965pay.7.1348830004882;
        Fri, 28 Sep 2012 04:00:04 -0700 (PDT)
Path: t10ni23591749pbh.0!nntp.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin3!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From: Uwe Klein <u...@klein-habertwedt.de>
Newsgroups: comp.lang.tcl
Subject: Re: How to interrupt a task which is running in a thread?
Date: Fri, 28 Sep 2012 12:58:39 +0200
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <vfcgj9-ada.ln1@klein-habertwedt.de>
References: <9045bde7-7f2c-4b82-8fb0-5a58f7292e2c@googlegroups.com> <70923e8b-aa74-4b28-b655-255e6b06fbce@googlegroups.com> <scb9s.10882$7s4.10634@fed05.iad> <5cd19719-a2df-4b8e-916c-f5e68a8f6cdb@googlegroups.com> <d81gj9-vt8.ln1@klein-habertwedt.de> <ba98c5f3-e8b5-453e-b216-f9385c646d26@googlegroups.com>
Mime-Version: 1.0
Injection-Info: mx04.eternal-september.org; posting-host="3bc0ca029b2d3aac2bb35b2ba92ac093";
	logging-data="6674"; mail-complaints-to="ab...@eternal-september.org";	posting-account="U2FsdGVkX18R9egSeKikZpkFFONJ8iXfHQq+0wKeP2U="
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040114
In-Reply-To: <ba98c5f3-e8b5-453e-b216-f9385c646d26@googlegroups.com>
X-Accept-Language: en-us, en
Cancel-Lock: sha1:nebaL9xRntPV2iBCNEWlLDLx35o=
Bytes: 2634
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Andy wrote:
> Another question, how to get output message? I mean the message generated by ping command.

#!/usr/bin/wish

button  .start  -text Start -command {handlecmd X start}
button  .stop   -text Stop  -command {handlecmd X stop}
grid    .start  .stop

# create a loop filedescriptor, there are various other ways
# to achieve the same:
set ::pfd [open |cat  RDWR  ]
fconfigure $::pfd -buffering none

# create an event handler for (returning) output
# and a proc to handle events:
proc outputevent {fd} {
         puts stderr PFD:[ gets  $fd ]
}
fileevent $::pfd readable [list outputevent $::pfd]

proc handlecmd {_id action} {
         upvar ::$_id id
         switch -- $action \
         start {
                 if {![catch {set id} cerr]} {
                         puts stderr "Task runs already"
                         return
                 }
		# redirect all output to a file desciptor:
                 set id [ exec ping localhost >&@ $::pfd & ]
         } stop {
                 if {[catch {set id} cerr]} {
                         puts stderr "Task does not run"
                         return
                 }
                 exec kill $id
                 unset id
         }
}

uwe