gogins / csound-extended

Extensions for Csound including algorithmic composition, Android app, and WebAssembly.
GNU Lesser General Public License v2.1
40 stars 1 forks source link

Deadlock in playpen #169

Closed gogins closed 3 years ago

gogins commented 3 years ago

With more happening as I build out a useful UI for Drone-2.csd, the playpen freezes after clicking on the play audio button. This is since either (a) I added more widgets to the UI, or (b) I began piping stderr into the messages TextView.

This is the best API reference: https://lazka.github.io/pgi-docs/

gogins commented 3 years ago

Using valgrind --tool=helgrind shows possible data races in the JSC library. I will research JSC issues.

gogins commented 3 years ago

GLib is not valgrind-friendly, leading to many false positives: https://gitlab.gnome.org/GNOME/glib/-/issues/947.

gogins commented 3 years ago

Running with valgrind --error-limit=no --tool=helgrind python3.7 playpen.py ~/michael.gogins.studio/music/sounds_with_internals/Drone-2.csd shows that sound continues to play while the UI is frozen. Perhaps there is a conflict between Python logging and PyObject-GTK.

gogins commented 3 years ago

Not using the logging.getLogger().debug -- no help.

Not using inspect.currentFrame() -- no help.

Not using the ConsoleMessageCaptor -- runs fine!

Using the ConsoleMessageCaptor but without the IOChannel watch -- runs fine!

gogins commented 3 years ago

The bug appears to be caused by using IOChannel.readline when the IO_IN condition is not for a whole line.

Indeed, there is a recent bug here: https://discourse.gnome.org/t/trying-to-understand-glib-iochannel-read-chars-under-python/5798/6

I will try os.read. But then the logic is tricky and it is hard to avoid a blocking read.

I have moved all message logging back to the console, and disabled the messages pane. I am closing this issue for now until a solution is found.

Ideally, the IOChannel would be polled and only available data would be read, until a newline was read, then the data would be written as a whole line.