Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition with exitEvent #192

Open
matthijskooijman opened this issue Oct 12, 2019 · 0 comments
Open

Race condition with exitEvent #192

matthijskooijman opened this issue Oct 12, 2019 · 0 comments

Comments

@matthijskooijman
Copy link
Contributor

Issue Report

Description

There is a race condition when a player is started and very quickly exits, before the code has a chance to register an exitEvent handler.

Problem reproduction

The following program wants to print "Exit", but does not. The sleep in there is to artificially enlarge the window for the race condition to occur. Without the sleep, this will usually print "Exit", but there might be rare cases where the process quits before the exitEvent is registered.

from omxplayer.player import OMXPlayer
from pathlib import Path
from time import sleep

player = OMXPlayer(Path("/dev/null"))
sleep(1)
player.exitEvent += lambda p, e: print("Exit")

A structure like this is important for a program that wants to keep playing things. That needs some way to guarantee that the exitEvent handler is always run, so it can start playing something else even when the player exits immediately due to whatever reason.

AFAICS, there is currently no way to fix this race condition. To do so, you would need to register the exitEvent before the player is started, which is currently impossible.

Maybe a solution could be combined with #161, which suggests adding a no-argument constructor to start a player and a load() method to switch to a different source. If that constructor would not start the player, just construct the object and there would be either a separate start() method, or the first call to load() would start the player, then there would be a safe window to register the exitEvent handler.

Environment details

  • OS (lsb_release -a):
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
Software Version
python-omxplayer-wrapper 0.3.2
python-dbus (dpkg -s python-dbus) 1.2.12
python (python --version) 3.7.3
omxplayer (omxplayer --version) f543a0d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant