Comments (13)
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.
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.
from pywebview.
The message to post on the issue when closing it. If none provided, will not comment when closing an issue.
from pywebview.
Related Issues (20)
- Different menus for different windows? HOT 6
- how to overlay on top of the webview or make the webview and kivy main window one. HOT 5
- Frameless Window Broken AF HOT 4
- storage_path doesn't seem to work HOT 5
- Some computers cannot start pywebview properly HOT 5
- Pystray Icon HOT 2
- Whether this tool can support the installation of extensions HOT 3
- Is it possible to set up proxies for each window? HOT 5
- Is there a way to hide this HOT 3
- How can I set the background color of the header in macOS? HOT 3
- ability to return binary data to frontend HOT 4
- [URGENT] A ticking sound happens when clicking on keyboard keys! HOT 3
- DIfferent min working area sizes being set using min_size on different OS HOT 2
- on_loaded() missing 1 required positional argument: 'window' HOT 1
- create_window does not support url hash for single page applications HOT 3
- native splash screen before loading a page completely HOT 4
- Deadlock while closing the window with persistent threads running on Windows (again) HOT 7
- The program is not displayed on the status bar HOT 5
- Can`t access python code: unhashable type: 'ConfigParser' HOT 9
- gui=mshtml js error Expected ‘:’ HOT 2
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.