fileevent fired permanently causing infinite loop 
Author Message
 fileevent fired permanently causing infinite loop

The following tcl script runs into an infinite loop,
(provided that the file /var/log/messages exists).
If eof has been reached, the file is STILL readable,
causing the fileevent to be fired permanently.
Has anybody an idea how to fix this issue?
(The expected behavior is: read the file till
eof and then continue reading after more input
is available...):

  pack [text .t] -expand yes -fill both

  proc read_data {fid} {
    while {![eof $fid]} {
      set input [read $fid]
      .t insert end $input
      .t see end
    }
  }

  set fn {/var/log/messages}
  wm title . "Logfile: $fn"
  set fid [open $fn r]
  fconfigure $fid -blocking 0
  fileevent $fid readable {read_data $fid}
  update idletasks

I have ActiveTcl 8.3.4. running under SuSE linux 6.4.
Any help would be appreciated.

    Jochen
--
(remove "nospam_" when replying)



Sat, 24 Jul 2004 21:31:55 GMT  
 fileevent fired permanently causing infinite loop

Quote:

> The following tcl script runs into an infinite loop,
> (provided that the file /var/log/messages exists).
> If eof has been reached, the file is STILL readable,
> causing the fileevent to be fired permanently.
> Has anybody an idea how to fix this issue?
> (The expected behavior is: read the file till
> eof and then continue reading after more input
> is available...):

>   pack [text .t] -expand yes -fill both

>   proc read_data {fid} {
>     while {![eof $fid]} {
>       set input [read $fid]
>       .t insert end $input
>       .t see end
>     }
>   }

>   set fn {/var/log/messages}
>   wm title . "Logfile: $fn"
>   set fid [open $fn r]
>   fconfigure $fid -blocking 0
>   fileevent $fid readable {read_data $fid}
>   update idletasks

> I have ActiveTcl 8.3.4. running under SuSE linux 6.4.
> Any help would be appreciated.

This is known, expected, documented behavior. Your event handler
should recognize an eof condition and close the descriptor.

fileevent on normal files aren't that useful. you are looking at
monitoring a file for updates like a Unix tail. see http://mini.net/tcl/1154.html
for info on how to implement this.

Bruce



Sat, 24 Jul 2004 22:16:41 GMT  
 fileevent fired permanently causing infinite loop


Quote:
> This is known, expected, documented behavior. Your event handler
> should recognize an eof condition and close the descriptor.

> fileevent on normal files aren't that useful. you are looking at
> monitoring a file for updates like a Unix tail. see

http://mini.net/tcl/1154.html

Quote:
> for info on how to implement this.

Thank you Bruce,

that was EXACTLY I was looking for :-)

Jochen

--
(remove "nospam_" when replying)



Sat, 24 Jul 2004 22:47:39 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. fileevent handler goes into an infinite loop

2. Why is fileevent $socket writable is infinite loop?

3. fileevent infinite loop

4. Boolean Proc causes Infinite Loop - Need Help

5. Infinite loops

6. Headless VW3.0 hangs/infinite-loops while creating or copying a large ByteString

7. infinite loops

8. Infinite loop Process Problem

9. Infinite Loop

10. Infinite Loop

11. Best way to prevent infinite loops...

12. Best way to prevent infinite loops...

 

 
Powered by phpBB® Forum Software