matthias4217 / jukebox-ultra-nrv

Multi-user jukebox for LAN use
https://gitlab.com/club-jeux-int/jukebox-ultra-nrv
3 stars 3 forks source link

Jukebox not compatible with Python 3.7 #51

Closed PaulDance closed 5 years ago

PaulDance commented 5 years ago

When executed in Python version 3.7, the asynchronous routine calls generate Exceptions like this:

Exception in callback MPV.__init__.<locals>.mpv_event_extractor() at /usr/local/lib/python3.7/dist-packages/mpv.py:276
handle: <Handle MPV.__init__.<locals>.mpv_event_extractor() at /usr/local/lib/python3.7/dist-packages/mpv.py:276>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 254, in _event_generator
    raise StopIteration()
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 278, in mpv_event_extractor
    for event in _event_generator(self.handle):
RuntimeError: generator raised StopIteration
Exception in thread Thread-27:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/hackademint/jukebox-ultra-nrv/jukebox/__init__.py", line 27, in player_worker
    self.mpv = MyMPV(None)  # we start the track
  File "/home/hackademint/jukebox-ultra-nrv/jukebox/src/MyMPV.py", line 10, in __init__
    self.playlist_pos = 0
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 493, in setter
    _mpv_set_property_string(self.handle, name.encode(), str(proptype(value)).encode())
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 174, in wrapper
    ErrorCode.raise_for_ec(func, *args)
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 59, in raise_for_ec
    raise ex(ec, *args)
AttributeError: ('mpv property is not available', -10, <MpvHandle object at 0x7f39c1724bf8>, b'playlist-pos', b'0')

Exception in callback MPV.__init__.<locals>.mpv_event_extractor() at /usr/local/lib/python3.7/dist-packages/mpv.py:276
handle: <Handle MPV.__init__.<locals>.mpv_event_extractor() at /usr/local/lib/python3.7/dist-packages/mpv.py:276>
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 254, in _event_generator
    raise StopIteration()
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/local/lib/python3.7/dist-packages/mpv.py", line 278, in mpv_event_extractor
    for event in _event_generator(self.handle):
RuntimeError: generator raised StopIteration

When looking it up, it seems to be due to python3.7 changing the way things work in asyncio (PEP 479), thus introducing this new bug. The fix that is adviced is to surround generator yields with a try-except clause. For example:

yield next(seq)

needs to be replaced by:

try:
    yield next(seq)
except StopIteration:
    return

Although the exception in itself seems to be raised by mpv, making the jukebox available to python3.7 shouldn't be too much of a hassle. If it is really too complex to solve yourselves, maybe consider declaring the jukebox to require python3.6 for now ?

matthias4217 commented 5 years ago

I'm running Python3.7 and I don't get this issue. The exception was raised inside python-mpv so I don't have much control over it directly, but I can catch it as soon as I get it inside my code. (I can send a pull request though.) I'll be investigating on it.

matthias4217 commented 5 years ago

I can confirm it fine works on two different configurations : ArchLinux with Python 3.7.3 and Debian Testing with Python 3.7.3rc1. Which version of Python are you using exactly ?

PaulDance commented 5 years ago

Yes, it runs on a Debian-like using Python 3.7.3rc1, which was weird. But when you said the library was called python-mpv, I started investigating if I had the correct one, because upon installation, I selected mpv. After looking up, I realised mpv's information actually points to python-mpv's GitHub, so I figured mpv could be an old version of python-mpv, but it would seem weird for it to be still available. Removing mpv and replacing it by python-mpv seemed to have fixed the issue. So everything looks good after all... my bad, I guess.

Maybe adding precisely python-mpv as a Python library to install using pip in the installation instructions could be useful ? Finally, should I close down this issue now that I found a solution ?

matthias4217 commented 5 years ago

Okay my bad, I didn't update the README. I'll clean up the installation process. To install required python modules, rup pip -r requirements.txt