A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/r0x0r/pywebview/issues/720 below:

Crash on Windows when opened from system tray · Issue #720 · r0x0r/pywebview · GitHub

Specification Description

I use pywebview along with pystray (0.17.3) as part of a script that occasionally needs to pop up a login window. Because both pywebview and pystray need to run on the main thread, I open the webview from a click on the system tray icon, as shown in the basic example below. This action runs on the main thread, and on macOS and Ubuntu it works with no issues. On Windows it gives the following error:

Unhandled Exception: Python.Runtime.PythonException: OSError : [WinError 1402] Invalid cursor handle.
   at Python.Runtime.Dispatcher.Dispatch(ArrayList args)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

A minimum example to demonstrate the issue is given below. Run this code on Windows and you will see a black square appear in the system tray. Right-click the icon and click the Webview option to trigger the crash. I've also added the thread names to show that both pystray and pywebview are running on the main thread:

import pystray, webview, threading
from PIL import Image

def click(icon, item):
    print('pywebview thread:', threading.current_thread().__class__.__name__)
    window = webview.create_window('Woah dude!', 'https://pywebview.flowrl.com')
    webview.start()

if __name__ == '__main__':
    print('pystray thread:', threading.current_thread().__class__.__name__)
    pystray.Icon('test', Image.new('RGB', (16, 16)), menu=pystray.Menu(pystray.MenuItem('Webview', click))).run()
Practicalities

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4