trainman419 / python-cec

Other
171 stars 42 forks source link

remove_callback "error return without exception set" #26

Closed xaguzman closed 6 years ago

xaguzman commented 6 years ago

I am getting this error whenever I try to call the remove_callback method, I am succesful to initialize and add callbacks to my functions, however, after I am done with the CEC controls, I am unable to remove the callbacks.

This is being used in a raspberry pi boot up menu, and it runs continuously, after the user selects the boot option, I would like to disable the cec controls, thus, this script is never going to quit / finish.

Is there any special consideration to remove callbacks?

Here's the code used:

import cec
from time import sleep
import uinput

#cec.init()

#tv = cec.Device(cec.CECDEVICE_TV)
#tv.power_off()
#sleep(5)
#tv.power_on()

device = uinput.Device([
    uinput.KEY_DOWN,
    uinput.KEY_UP,
    uinput.KEY_A,
    uinput.KEY_ENTER,
    uinput.KEY_RED,
    uinput.KEY_1,
    uinput.KEY_2,
    uinput.KEY_3,
    uinput.KEY_4,
    uinput.KEY_5,
    uinput.KEY_6
    ])

keymap = {
    1: uinput.KEY_1,
    2: uinput.KEY_2,
    3: uinput.KEY_3,
    4: uinput.KEY_4,
    5: uinput.KEY_5,
    6: uinput.KEY_6,
    7: uinput.KEY_ENTER,
    8: uinput.KEY_DOWN,
    9: uinput.KEY_UP
    }

def __keypress_cb__(event, *args):
    print("Got event", event, "with data", args)
    #placeholder code below
    #keycode = 1
    #device.emit_click(keymap[keycode])

def start():
    global started
    if started==False:
        cec.add_callback(__keypress_cb__, cec.EVENT_KEYPRESS)
        started=True

def stop():
    global started
    if started==True:
        cec.remove_callback(__keypress_cb__, cec.EVENT_KEYPRESS)
        started=False

cec.init()
cec.remove_callback(
tv = cec.Device(0)
started=False
nforro commented 6 years ago

It was a bug in remove_callback implementation, it should work fine now.

xaguzman commented 6 years ago

Excuse me for the dumb question...not an experienced python user.

How can I get the latest changes? I tried updating via pip:

sudo pip install cec --upgrade

But it tells me that the package is updated, do I need to pull from source?

nforro commented 6 years ago

You would have to wait for a new release to be able to install it from pypi.

Use the following command to install from current master:

sudo pip install git+https://github.com/trainman419/python-cec.git@master#egg=cec