Python 3.x 使用evdev InputDevice退出python程序会导致错误

Python 3.x 使用evdev InputDevice退出python程序会导致错误,python-3.x,controller,evdev,Python 3.x,Controller,Evdev,我正在尝试使用evdev将控制器作为输入设备。当我退出程序时,会收到一条错误消息,指出delete方法(super)至少需要一个参数。我已经看过了,但我们无法找到一个解决方案来妥善处理这个问题 该方案: # import evdev from evdev import InputDevice, categorize, ecodes # creates object 'gamepad' to store the data # you can call it whatever you like g

我正在尝试使用evdev将控制器作为输入设备。当我退出程序时,会收到一条错误消息,指出delete方法(super)至少需要一个参数。我已经看过了,但我们无法找到一个解决方案来妥善处理这个问题

该方案:

# import evdev
from evdev import InputDevice, categorize, ecodes

# creates object 'gamepad' to store the data
# you can call it whatever you like
gamepad = InputDevice('/dev/input/event5')

# prints out device info at start
print(gamepad)

# evdev takes care of polling the controller in a loop
for event in gamepad.read_loop():
    # filters by event type
    if event.type == ecodes.EV_KEY and event.code == 308:
        break
    if event.type == ecodes.EV_ABS and event.code == 1:
        print(event.code, event.value)
    if event.type == ecodes.EV_ABS and event.code == 0:
        print(event.code, event.value)
    # print(categorize(event))
    if event.type == ecodes.EV_KEY:
        print(event.code, event.value)
当我使用特定的键时,我会中断循环,导致以下错误消息:

Exception TypeError: TypeError('super() takes at least 1 argument (0 given)',) in <bound method InputDevice.__del__ of InputDevice('/dev/input/event5')> ignored
异常TypeError:忽略中的TypeError('super()至少接受1个参数(给定0)')
使用
^C
退出时也会发生同样的情况。
您知道如何正确处理退出吗?

简单地说,evdev正在等待事件发生,而您突然中断了循环

要正确退出执行,请删除break语句,关闭设备并结束脚本

[...]
for event in gamepad.read_loop():
    if event.type == ecodes.EV_KEY and event.code == 308:
        gamepad.close()   #method of ..yourpythonlib/evdev/device.py
        quit()            
[...]
要使用
^C
快速退出而不出现错误,您仍然需要使用“try-except块”关闭evdev输入设备

for event in gamepad.read_loop():
   try:
       [...] if event [...]
   except KeyboardInterrupt:
       gamepad.close()
       raise