Improvement to imports, what is a better way ?

Cameron Simpson cs at cskk.id.au
Thu Jan 19 18:04:14 EST 2023


On 19Jan2023 07:34, Dan Kolis <dankolis at gmail.com> wrote:
>On Thursday, January 19, 2023 at 12:09:02 AM UTC-5, cameron wrote:
>> I know this is vague. Once you find its stalling in a particular
>> function (if it is) you may be able to run that function directly. Also,
>> a print() at the top abd bottom/return of the stalling function. And so
>> on.
>
>Dan says:
>After lots of iterations, I changed one line in a call used to refresh 
>windows from .update() to .update_idle_tasks()

Yeah. See the bottom of this page:
https://tkdocs.com/tutorial/eventloop.html

>Some other dudes were so nice they tested it before that, it worked perfectly on their computers anyway.

This kind of thing can be timing and user interaction sensitive.

>Now it seems to work 'all the way' too after this change on my favroritish computer.
>Since a CTRL C often started it going again I had a hint there, reading 
>other peoples various troubles all over the web made me think it was 
>'someplace in this part'.

The `update_idle_tasks()` call runs pending display updates (i.e.  
redraws) but does not process any events (mostly user actions). So it 
generally returns promptly.

The `update()` call processes events as well. If those events make 
callbacks, the callbacks can block (depending what they do). Or they 
themselves might call update() if you've written your code that way.

There's a note on the page mentioned above.

Calling update() effectively runs the main event loop _here_, at the 
call. This is also how things like interactive dialogue boxes work: draw 
the dialogue, then internally call update() to process user interaction 
until the dialogue is done, then return.

This description is lousy, and we'd need to see the code to pin point 
exactly how your interface is deadlocking (or, possibly, just pausing 
for a long time while something happens).

But the key points are:
- there's no threading in the stuff above, so if you need GUI updates 
   _during_ some process you need to _call_ the GUI main loop for it to 
   do some work - you've blocked until that call comes back, like any 
   other function call
- the update_idle_tasks just does redraws; because it doesn't process 
   events those events' callbacks do not run, therefore those callbacks 
   cannot block your current code
- the update function does the full mainloop, including processing 
   events, and processing events can make callbacks, whcih can themselves 
   call update etc and ...

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list