-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy (xclip backend) hangs when called in side shell command substitution #116
Comments
Well, it seems that
Could you make |
It seems to be less buggy. See asweigart#116 (comment) Closes asweigart#116
It seems that stdout must be closed, duped to import multiprocessing
import pyperclip
import os
def pyperclip_copy_wrapper(text):
# Dup stdout to devnull
fdnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(fdnull, 1)
try:
pyperclip.copy(text)
finally:
os.close(1)
os.close(fdnull)
def copy_to_clipboard(text):
p = multiprocessing.Process(name='copy-to-clipboard', target=pyperclip_copy_wrapper, args=(text,))
p.start()
p.join()
return p.exitcode This works with both Btw, |
Or alternatively, just import os
import pyperclip
def copy_to_clipboard(text):
stdoutfd_dup = os.dup(1)
fdnull = os.open(os.devnull, os.O_WRONLY)
try:
os.dup2(fdnull, 1)
pyperclip.copy(text)
finally:
# Restore stdout FD and close temporary ones
os.dup2(stdoutfd_dup, 1)
os.close(stdoutfd_dup)
os.close(fdnull) |
This appears to be the documented behavior of its default
echo "foo" | xclip -selection clipboard | cat
<hangs> echo "foo" | xclip -selection clipboard -silent | cat
<hangs> It doesn't hang for me (xclip 0.13 on Linux (Arch)) if it's instructed to work as a filter (i.e. kept in the foreground) via the echo "foo" | xclip -selection clipboard -f | cat
foo |
Installing |
Hello,
OS: Debian unstable linux-amd64
Pyperclip 1.6.0
Backend in use:
xclip
Shell: zsh, dash
pyperclip.copy()
hangs when called inside shell's command substitution. When xclip executes, python process is gone whilexclip
stays up running. But it seems to be Python3-ony problem, Python2 is fine.The text was updated successfully, but these errors were encountered: