forked from trav/lintunes
v0.73.1: opening DJ mode no longer crashes after enough openings
Each opening started a new audio thread, and Qt's PipeWire backend leaks
~24 file descriptors per thread that ends. At the desktop's 1024-fd limit
QAudioSink.start() failed ("Too many open files") and segfaulted in
pw_stream_connect. The thread now lives as long as the output: stop()
only silences the pump, shutdown() (window close / aboutToQuit) ends it.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||
|
||||
__version__ = "0.73.0"
|
||||
__version__ = "0.73.1"
|
||||
|
||||
+22
-6
@@ -37,8 +37,9 @@ class _Pump(QObject):
|
||||
# Follow the system's output: a sink is opened on one device, and
|
||||
# when that goes (headphones in, Bluetooth on) Qt doesn't move it —
|
||||
# it just stops, and the decks went silent until DJ mode reopened.
|
||||
self.devices = QMediaDevices()
|
||||
self.devices.audioOutputsChanged.connect(self._reopen)
|
||||
if getattr(self, "devices", None) is None:
|
||||
self.devices = QMediaDevices()
|
||||
self.devices.audioOutputsChanged.connect(self._outputs_changed)
|
||||
self.timer = QTimer()
|
||||
self.timer.setInterval(TICK_MS)
|
||||
self.timer.timeout.connect(self._fill)
|
||||
@@ -71,6 +72,11 @@ class _Pump(QObject):
|
||||
self._close()
|
||||
self._open()
|
||||
|
||||
@pyqtSlot()
|
||||
def _outputs_changed(self):
|
||||
if self.timer is not None: # stopped: nothing to move
|
||||
self._reopen()
|
||||
|
||||
def _fill(self):
|
||||
if self.sink is None or self.io is None:
|
||||
# No device a moment ago; try again about once a second.
|
||||
@@ -126,7 +132,7 @@ class DjOutput(QObject):
|
||||
from PyQt6.QtCore import QCoreApplication
|
||||
app = QCoreApplication.instance()
|
||||
if app is not None:
|
||||
app.aboutToQuit.connect(self.stop)
|
||||
app.aboutToQuit.connect(self.shutdown)
|
||||
|
||||
@property
|
||||
def latency_frames(self) -> int:
|
||||
@@ -136,13 +142,23 @@ class DjOutput(QObject):
|
||||
if self._running:
|
||||
return
|
||||
self._running = True
|
||||
self._thread.start()
|
||||
if not self._thread.isRunning():
|
||||
self._thread.start()
|
||||
self._go.emit()
|
||||
|
||||
def stop(self):
|
||||
"""Silence: the sink closes, the thread stays for the next start.
|
||||
Qt's PipeWire backend never frees what it set up in a thread that
|
||||
ends — ~24 file descriptors a thread — so one per DJ-mode opening
|
||||
ran the app out of them (limit 1024) and the sink's start crashed."""
|
||||
if not self._running:
|
||||
return
|
||||
self._running = False
|
||||
self._halt.emit()
|
||||
self._thread.quit()
|
||||
self._thread.wait(2000)
|
||||
|
||||
def shutdown(self):
|
||||
"""The app is ending: the thread ends too."""
|
||||
self.stop()
|
||||
if self._thread.isRunning():
|
||||
self._thread.quit()
|
||||
self._thread.wait(2000)
|
||||
|
||||
@@ -1577,6 +1577,12 @@ class DjShelf(QWidget):
|
||||
for v in self.views:
|
||||
self._refresh_deck(v)
|
||||
|
||||
def shutdown(self):
|
||||
"""The window is closing: stopped, and the audio thread ends."""
|
||||
self.stop()
|
||||
if self._output is not None:
|
||||
self._output.shutdown()
|
||||
|
||||
def set_visualizer(self, visualizer):
|
||||
"""Feed the mix to the transport's visualizer (None: stop)."""
|
||||
if self._visualizer is not None and visualizer is None:
|
||||
|
||||
@@ -2940,7 +2940,7 @@ class MainWindow(QMainWindow):
|
||||
self._cast.shutdown()
|
||||
self._airplay.shutdown()
|
||||
if self._dj is not None:
|
||||
self._dj.stop() # its audio thread must end before Qt does
|
||||
self._dj.shutdown() # its audio thread must end before Qt does
|
||||
self.player.shutdown()
|
||||
self.player.loudness.save()
|
||||
self._manager.flush()
|
||||
|
||||
Reference in New Issue
Block a user