• My application freezes

    From Luc@21:1/5 to All on Tue Dec 13 06:56:31 2022
    This Tk application uses a while infinite loop. Upon each iteration,
    it checks a boolean variable that I can toggle with a key binding.
    If the value is 0, the loop continues but does nothing because of
    the first line:

    if {$::GO == 0} {continue}

    The activity stops as expected, but then it becomes unresponsive.
    I can't untoggle, I can't do anything.

    What is the correct way of doing what I want?

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Dec 13 11:18:09 2022
    * Luc <[email protected]>
    | This Tk application uses a while infinite loop. Upon each iteration,
    | it checks a boolean variable that I can toggle with a key binding.
    | If the value is 0, the loop continues but does nothing because of
    | the first line:

    | if {$::GO == 0} {continue}

    | The activity stops as expected, but then it becomes unresponsive.
    | I can't untoggle, I can't do anything.

    That's because mouse clicks are handled by the event loop.
    Losely spoken, the event loop runs only if there is nothing else to do,
    and cleary the above tight loop is "something" to do ;-)

    | What is the correct way of doing what I want?

    Check 'vwait' or 'tkwait variable' if you want to wait for a variable to
    be set while the GUI stays responsive:
    https://www.tcl.tk/man/tcl/TclCmd/vwait.html
    https://www.tcl.tk/man/tcl/TkCmd/tkwait.html

    or 'update' if you need to give the GUI a go during a runnning calculation
    https://www.tcl.tk/man/tcl/TclCmd/update.html
    (but be aware of
    https://wiki.tcl-lang.org/page/Update+considered+harmful
    )

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Heller@21:1/5 to [email protected] on Tue Dec 13 13:14:22 2022
    At Tue, 13 Dec 2022 11:18:09 +0100 Ralf Fassel <[email protected]> wrote:


    * Luc <[email protected]>
    | This Tk application uses a while infinite loop. Upon each iteration,
    | it checks a boolean variable that I can toggle with a key binding.
    | If the value is 0, the loop continues but does nothing because of
    | the first line:

    | if {$::GO == 0} {continue}

    | The activity stops as expected, but then it becomes unresponsive.
    | I can't untoggle, I can't do anything.

    That's because mouse clicks are handled by the event loop.
    Losely spoken, the event loop runs only if there is nothing else to do,
    and cleary the above tight loop is "something" to do ;-)

    | What is the correct way of doing what I want?

    Check 'vwait' or 'tkwait variable' if you want to wait for a variable to
    be set while the GUI stays responsive:
    https://www.tcl.tk/man/tcl/TclCmd/vwait.html
    https://www.tcl.tk/man/tcl/TkCmd/tkwait.html

    or 'update' if you need to give the GUI a go during a runnning calculation

    Specificly, "update idletasks" should be included in any "loop" in a Tk application:

    while {sometest} {
    some processing...
    update idle
    }


    https://www.tcl.tk/man/tcl/TclCmd/update.html
    (but be aware of
    https://wiki.tcl-lang.org/page/Update+considered+harmful
    )

    "update idletasks" is generally "safe". This limits the event loop to necessary "idle" tasks.


    HTH
    R'



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    [email protected] -- Webhosting Services

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Tue Dec 13 16:53:12 2022
    Luc <[email protected]> wrote:
    This Tk application uses a while infinite loop.

    Why? That will block the event loop from running.

    Upon each iteration, it checks a boolean variable that I can toggle
    with a key binding. If the value is 0, the loop continues but does
    nothing because of the first line:

    if {$::GO == 0} {continue}

    The activity stops as expected, but then it becomes unresponsive.
    I can't untoggle, I can't do anything.

    Your description seems reversed. Once the 'infinite loop' starts, then
    the UI should become unresponsive.

    What is the correct way of doing what I want?

    Tell us what "you want to do" -- then we can answer with better
    answers.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)