Comments (11)
The problem with multiprocessing is that a Window
object cannot be serialised because of threading events. Unability to serialise Window
is rather a show stopper. Non-blocking start()
can be implemented without multiprocessing on all the platforms but Cocoa.
I have tried to implement this, but could not find an adequate solution. Help is welcomed.
from pywebview.
The problem with multiprocessing is that a
Window
object cannot be serialised because of threading events. Unability to serialiseWindow
is rather a show stopper. Non-blockingstart()
can be implemented without multiprocessing on all the platforms but Cocoa. I have tried to implement this, but could not find an adequate solution. Help is welcomed.
Why do you need to serialise the Window object?
Louis
from pywebview.
You might want to access a Window
objects in your application code. For that you need to pass them between processes and they need to be serialised first.
from pywebview.
You might want to access a
Window
objects in your application code. For that you need to pass them between processes and they need to be serialised first.
What I mean is the Window object (in its current state) can sit in the other process.
Then another 'window' object (which would replace the old one) could be used which only communicates with the other object running in the other process
from pywebview.
Essentially all you would need to write is a wrapper for a new window class, and a controller which sits in the other process and keeps everything up to date
from pywebview.
I am afraid I do not follow. How would you rewrite following code in multiprocessing? This is identical to passing a function with a parameter to start
from time import sleep
from threading import Thread
import webview
"""
Loading new HTML after the window is created
"""
def load_html(window):
sleep(5)
window.load_html('<h1>This is dynamically loaded HTML</h1>')
if __name__ == '__main__':
window = webview.create_window('Load HTML Example', html='<h1>This is initial HTML</h1>')
t = Thread(target=load_html, args=(window,))
t.start()
webview.start()
from pywebview.
I am afraid I do not follow. How would you rewrite following code in multiprocessing? This is identical to passing a function with a parameter to
start
from time import sleep from threading import Thread import webview """ Loading new HTML after the window is created """ def load_html(window): sleep(5) window.load_html('<h1>This is dynamically loaded HTML</h1>') if __name__ == '__main__': window = webview.create_window('Load HTML Example', html='<h1>This is initial HTML</h1>') t = Thread(target=load_html, args=(window,)) t.start() webview.start()
Something like this:
from time import sleep
from threading import Thread
import webview
#
# this runs in a seperate process
#
class ActualWindow:
...
def loop(self):
while 1:
method_name, args = self.mp_queue.get()
method = getattr(self, method_name)
method(*args)
#
# dummy Window class, which is instansiated in the main process
#
class Window():
...
def load_html(self, html: str):
self.mp_queue.put(('load_html', (html)));
if __name__ == '__main__':
window = webview.create_window('Load HTML Example', html='<h1>This is initial HTML</h1>')
webview.start(block=False)
sleep(5)
window.load_html('<h1>This is dynamically loaded HTML</h1>')
from pywebview.
The thing is pywebview itself is using window objects internally. In your example you create a window object in the main process. How do you pass it to the process in webview.start()
?
from pywebview.
The thing is pywebview itself is using window objects internally. In your example you create a window object in the main process. How do you pass it to the process in
webview.start()
?
The 'actual' window object is the one running in the other process ie the same process that webview is running in.
The only communication between the two processes is the 'dummy' classes or methods that send over a queue, which control the actual classes instantiated in the other process
from pywebview.
If all that is needed is a non-blocking webview.start()
, then why not just keep the current threading
implementation, but instead of running the backend logic callback in a thread, just create the main window in a thread and return immediately, allowing the backend logic to be implemented in the main thread? Considering that webview.start()
will already start all windows but the first in new threads, it's even a bit unexpected that it starts the first one in the main thread, requiring a separate callback for the backend logic to run that in a thread.
from pywebview.
@louisnw01 honestly I don't know if it is possible to split Window object in such a way. If you or somebody else get it working keeping API the same I can accept a PR.
@lanzz Cocoa requires GUI to be run on the main thread. Other platforms can be run in a thread as you described.
from pywebview.
Related Issues (20)
- iframe cannot call Python HOT 1
- Nuitka support HOT 7
- [WIN] Folder Dialog - New folder is renamed with a delay. HOT 3
- [Maybe bug] The todos app crashed immediately after I run "buildozer -v android debug deploy run" HOT 13
- google account logout after close the pywebview window HOT 4
- any way to edit the response headers (or somehow disable X-Frame-Options)? HOT 8
- How do I unround the corners of a borderless window? HOT 2
- [QUESTION] Can pywebview be embedded anywhere? HOT 2
- How can we lift the CORS restrictions in pywebview? HOT 3
- javascript print() not working with pywebview HOT 3
- There's a problem here HOT 2
- Modernize folderdialog? HOT 4
- [Feature] Message Box function HOT 5
- how Intercept and filter files or requests ? HOT 2
- `mypy` complains that `webview` doesn't have library stubs or `py.typed` marker HOT 1
- on Windows, create_file_dialog() is not disposing of dialog after ShowDialog() HOT 1
- "pip install pywebview" doesn't work : sha hash error HOT 1
- Can't use multiple pywebviews at the same time HOT 7
- cant click on elements when `window.transparent` is true HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywebview.