Re: Problem with Tcl_AsyncCreate()
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Problem with Tcl_AsyncCreate()

From: David Gravereaux <davygrvy@pobox.com>
Date: Tue Feb 28 2006 - 22:54:36 CET

san wrote:
> When I am trying to
> execute some other command on the command line, then the handler_safe()
> is being called.

You're not in the event loop. Tcl is blocked on stdin at that point and
most definitely can not do any background work. You need to add some
"fluffiness". Here's an example of non-blocking console reading:

# ----------------------------------------------------------------------
# Step #4, service the event loop according to the shell we are under.

if {![info exists tk_version] && ![info exists tcl_service]} {
    set long_command ""

    if {![info exists tcl_prompt1]} {
        set tcl_prompt1 {puts -nonewline "(ijgate) [history nextid] % "}
    }
    proc read_stdin {} {
        global eventLoop tcl_prompt1 long_command
        set l [gets stdin]
        if {[eof stdin]} {
             set eventLoop "done" ;# terminate the vwait eventloop
        } else {
             if {[string compare $l {}]} {
                 append long_command "\n$l"
                 set l $long_command
                 if {[info complete $l]} {
                     if {[catch {uplevel \#0 history add [list $l] exec} err]} {
                         puts stderr $err
                     } elseif {[string compare $err {}]} {
                         puts $err
                     }
                     set long_command ""
                     catch $tcl_prompt1
                 } else {
                     puts -nonewline "> "
                 }
             } elseif {![string compare $long_command {}]} {
                 catch $tcl_prompt1
             } else {
                 puts -nonewline "> "
             }
             flush stdout
        }
    }

    # set up our keyboard read event handler:
    # Vector stdin data to the socket
    fileevent stdin readable read_stdin

    catch $tcl_prompt1
    flush stdout
    # wait for and handle all events...
    vwait eventLoop
} elseif {[info exists tk_version]} {
    # Start a Tk UI?
}
Received on Sun Apr 30 02:18:05 2006