asweigart / pyperclip

Python module for cross-platform clipboard functions.
https://pypi.python.org/pypi/pyperclip
BSD 3-Clause "New" or "Revised" License
1.65k stars 196 forks source link

Fix Popen to prevent signal passthrough #265

Open shiribailem opened 3 months ago

shiribailem commented 3 months ago

Context: I'm using GKT4 so I have to use the xclip or xsel clipboards, my app monitors the clipboard and crashes anytime I try to use CTRL+C to copy text.

The reason and fix are straightforward, subprocess.Popen is passing through keyboard signals, so CTRL+C is killing the clipboard application being called.

The fix is outlined here: https://stackoverflow.com/questions/5045771/python-how-to-prevent-subprocesses-from-receiving-ctrl-c-control-c-sigint

Gist is to basically just add an intercept of the signals into Popen calls, which will keep the CTRL+C from being passed through.