pywayland icon indicating copy to clipboard operation
pywayland copied to clipboard

No signal can be received during Display.dispatch()

Open sloonz opened this issue 5 years ago • 2 comments

from pywayland.client import Display    
    
display = Display()    
display.connect()    
    
while True:    
    display.dispatch(block=True)    

This simple script ignores SIGINT (Control-C in a terminal). Adding signal.signal(signal.SIGUSR1, lambda *a: print("USR1")) shows that it ignores all signals.

The comparable C program does not display this behavior and can be stopped by pressing Control-C :

#include <stdio.h>     
#include <wayland-client.h>    
    
int    
main(int argc, char *argv[])    
{    
    struct wl_display *display = wl_display_connect(NULL);    
    while (wl_display_dispatch(display) != -1) {    
    }                
    wl_display_disconnect(display);                  
    return 0;                                       
}                                                   

sloonz avatar Jan 24 '21 23:01 sloonz

I can reproduce this. Any ideas on how to handle this?

Relevant issue: https://stackoverflow.com/a/14708549/3455614

The only workaround I've found is calling dispatch in a thread:

if __name__ == '__main__':
    Thread(target=main).start()
    while True:
        try:
            time.sleep(1)
        except KeyboardInterrupt:
            os.kill(os.getpid(), 9)

and3rson avatar Dec 07 '21 12:12 and3rson