Language/Python
[pywebview] subprocess 를 이용한 pywebview 분리 실행
TechNote.kr
2021. 9. 11. 16:54
728x90
pywebview를 실행하면 main thread 내에서 다른 코드 수행이 불가능하다.
이에 별도의 process로 분리하여 pywebview를 수행시키면 별도의 코드를 수행할 수 있다.
pywebview using subprocess · TechNoteGit/pywebview_example@540c4c9 (github.com)
import webview
from multiprocessing import Process, Pipe
def webview_subprocess(child_pipe):
window = webview.create_window('TechNote', 'https://technote.kr')
webview.start(cmd_recv, [window, child_pipe], gui='cef', debug=True)
def cmd_recv(window, child_pipe):
while True:
cmd = child_pipe.recv()
# To Do - cmd handler
if __name__ == '__main__':
parent_pipe, child_pipe = Pipe()
subprocess_handler = Process(target=webview_subprocess, args=(child_pipe,))
subprocess_handler.start()
subprocess_handler.join()
기본 process 와 pywebview를 실행하는 subprocess는 pipe를 통해 통신한다.
728x90