Created
February 7, 2018 13:34
-
-
Save ViktorOgnev/2701d3c5382d513622c97fdc61ab987f to your computer and use it in GitHub Desktop.
do webview stuff in separate process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import os | |
import threading | |
import time | |
import webview | |
def get_current_url(): | |
time.sleep(2) | |
print(webview.get_current_url()) | |
def execute_javascript(code): | |
code = code.strip() | |
print(webview.evaluate_js(code)) | |
print(f"code executed: {code}") | |
def loop(): | |
time0 = time.time() | |
while True: | |
bgcolor('#ffffff') | |
time.sleep(1) | |
get_current_url() | |
bgcolor('#212121') | |
time.sleep(1) | |
if time.time() - time0 < 10: | |
continue | |
webview.destroy_window() | |
os._exit(0) | |
def bgcolor(color): | |
# Change document background color and print document title | |
print( | |
webview.evaluate_js( | |
f"document.body.style.backgroundColor = '{color}';" | |
f"document.body.style.color = '#f2f2f2';")) | |
def gui(): | |
t = threading.Thread(target=loop) | |
t.start() | |
webview.create_window("Get current URL", "http://www.flowrl.com") | |
if __name__ == '__main__': | |
p = multiprocessing.Process(target=gui) | |
p.start() | |
print('some stuff done ') | |
time.sleep(15) | |
print('gui died but stuff is still getting done') | |
p.join() | |
print('we safely finish. And that is all') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment