diff --git a/feeluown/player/playlist.py b/feeluown/player/playlist.py index ad5b175de..d5af50251 100644 --- a/feeluown/player/playlist.py +++ b/feeluown/player/playlist.py @@ -118,7 +118,10 @@ def __init__(self, app: 'App', songs=None, playback_mode=PlaybackMode.loop, #: store value for ``songs`` property self._songs = DedupList(songs or []) # Acquire this lock before changing _current_song or _songs. - # TODO: use emit_nowait??? + # NOTE: some methods emit some signal while holding the lock, + # the signal handler should pay much attention to avoid deadlock. + # One thing is that the signal handler should not call any method + # that requires the lock!!! self._songs_lock = Lock() self.audio_select_policy = audio_select_policy @@ -166,13 +169,13 @@ def mode(self): def mode(self, mode): """set playlist mode""" if self._mode is not mode: + # we should change _mode at the very end + self._mode = mode if mode is PlaylistMode.fm: self._normal_mode_playback_mode = self.playback_mode self.playback_mode = PlaybackMode.sequential else: self.playback_mode = self._normal_mode_playback_mode - # we should change _mode at the very end - self._mode = mode self.mode_changed.emit(mode) logger.info('playlist mode changed to %s', mode) diff --git a/tests/player/test_playlist.py b/tests/player/test_playlist.py index 2db7c8cbf..4c8a05c43 100644 --- a/tests/player/test_playlist.py +++ b/tests/player/test_playlist.py @@ -187,8 +187,8 @@ def mock_prepare_metadata(mocker): async def test_playlist_change_mode(app_mock, mocker): # from normal to fm pl = Playlist(app_mock) - pl.mode = PlaylistMode.fm old_playback_mode = pl.playback_mode + pl.mode = PlaylistMode.fm assert pl.playback_mode is PlaybackMode.sequential # from fm to normal