etiennedub / pyk4a

Python 3 wrapper for Azure-Kinect-Sensor-SDK
MIT License
287 stars 81 forks source link

TypeError using with statement to read PyK4APlayback #180

Closed chrismeunier closed 1 year ago

chrismeunier commented 1 year ago

Hi I just found a bug when reading recordings using a with context. With a simple sample like so:

from pyk4a import PyK4APlayback

with PyK4APlayback("recording.mkv") as p: # call __enter__
    while True:
        try:
            p.get_next_capture()
            # do stuff
        except EOFError:
            break # get out of the with statement -> call __exit__

Upon exiting the with statement I get TypeError: __exit__() takes 1 positional argument but 4 were given. Which is actually normal because it takes 4 even if the others may be None. So I guess it's a simple fix, __exit__(self) just needs to be replaced by __exit__(self, exc_type, exc_value, traceback). I did it locally and it works just fine!

chrismeunier commented 1 year ago

Oh and while looking for help in playback.py I found a small typo: get_previous_capture() has an extra "e". 😉

lpasselin commented 1 year ago

Thanks for reporting with a fix! Should be an easy PR.

chrismeunier commented 1 year ago

Here you go! I'll leave it to you :)