-
-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add block
parameter to webview.start
using multiprocessing
#1384
Comments
The problem with multiprocessing is that a |
Why do you need to serialise the Window object? Louis |
You might want to access a |
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 |
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 |
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 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>')
|
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 |
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 |
If all that is needed is a non-blocking |
@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. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The message to post on the issue when closing it. If none provided, will not comment when closing an issue. |
Description
Hey @r0x0r,
I'd like to request an implementation of a non-blocking webview window, which runs the webview in a seperate process. This would eliminate the need for a callback function in
webview.start
, and would greatly increase the flexibility of this library.A basic example:
I implemented a very primitive and specialized version of this for my library; here is the source: https://github.com/louisnw01/lightweight-charts-python/blob/main/lightweight_charts/chart.py
I was running into a few issues with that, and I remember you mentioning that this was in the works, so I just wanted to bring it to your attention!
Thanks!
Louis
The text was updated successfully, but these errors were encountered: