moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.77k stars 245 forks source link

Exception on Linux. Maximum number of clients reached. #480

Open misiektw opened 2 years ago

misiektw commented 2 years ago

Linux 5.15, Xorg 21.1.3, Manjaro 21.3, pynput 1.7.6 (tested on master too)

Simple script based on examples:

from pynput.keyboard import Events

while True:
    with Events() as kevents:
        kevent = kevents.get(1.0)
    if kevent:
        print(kevent)

Throwing exceptions after few minutes of running, and stops processing keys:

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/home/misiek/Data/Games/EndlessSky/pynput/_util/__init__.py", line 210, in run
    self._run()
  File "/home/misiek/Data/Games/EndlessSky/pynput/keyboard/_xorg.py", line 545, in _run
    super(Listener, self)._run()
  File "/home/misiek/Data/Games/EndlessSky/pynput/_util/xorg.py", line 383, in _run
    self._display_record = Xlib.display.Display()
  File "/usr/lib/python3.10/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/usr/lib/python3.10/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/usr/lib/python3.10/site-packages/Xlib/protocol/display.py", line 166, in __init__
    raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0.0": b'Maximum number of clients reached'

Seems like depends on delay value. Shorter delay causing faster exception. But it's just my impression, not tested statistically.

GragaBot commented 1 year ago

I have the same issue. Any solution?

mezdahun commented 1 year ago

+1