开发者

Python + webkit + os.fork()

开发者 https://www.devze.com 2023-03-11 22:27 出处:网络
I have some troubles trying to callback webkit functions from a child process. This code are meant to load background resources and insert them by javascript asynchronously. I need to callback javascr

I have some troubles trying to callback webkit functions from a child process. This code are meant to load background resources and insert them by javascript asynchronously. I need to callback javascript functions once the resource is loaded while keep the interface working. I tried to sync threads throught pipes, but the while(1) polling in the main thread (to read the pipe) blocks the interface the same way as if the resource were loaded in the main. If I callback the webview.execute_script with javascript from the child process it does nothing except when I feed it with an alert like funcion, then breaks :S

Example given:

    import pygtk
    pygtk.require("2.0")

    import gtk,webkit,os

    class Browser:
        def __init__(self):
            self.window = gtk.Window()
            #self.window.set_decorated(False)
            self.window.set_default_size(800, 600)
            vbox = gtk.VBox()
            self.scroll_window = gtk.ScrolledWindow()
            self.webview = webkit.WebView()
            self.webview.set_transparent(True)
            self.window.add(self.webview)
            self.window.show_all()
            self.webview.load_u开发者_如何学Gori("http://google.es");
            self.error();

        def error(self):
            child_pid = os.fork()
            if child_pid == 0:
                self.webview.execute_script("""
                    alert(1);
                """)
                os._exit(0)

        def noerror(self):
            self.webview.execute_script("""
                alert(1);
            """)

    if __name__ == "__main__":
        browser = Browser()
        try:
          while True:
              gtk.main_iteration()
        except:
          gtk.main_quit()
          print "BAILING OUT!"

Thanks in advance!


webkit is not thread-safe.

See: http://markmail.org/message/4dwft6s6g6ptavj6

0

精彩评论

暂无评论...
验证码 换一张
取 消