r0x0r / pywebview

Build GUI for your Python program with JavaScript, HTML, and CSS
https://pywebview.flowrl.com
BSD 3-Clause "New" or "Revised" License
4.77k stars 555 forks source link

before_show callback not synchronous #1518

Open bweinlich opened 3 weeks ago

bweinlich commented 3 weeks ago

Specification

Description

I love the new before_show Event to set attributes before the window is actually shown. Unfortunately this only works if I set this manually:

my_window.events.before_show._should_lock = True

Otherwise there are unpredictable race conditions due to the new thread where my callback is executed. In fact most attributes have to be set before the window is shown so I think it has to be synchronous here.

Possible solutions: Creating the Event with this flag per default or at least make the "_should_lock" a part of the public api and document it.

Practicalities

r0x0r commented 1 week ago

I agree making the before_show blocking by default makes sense. It is a simple change, but must be tested for each platform first.