fluid-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [fluid-dev] Fluidsynth stops playing when stdout is piped


From: John O'Hagan
Subject: Re: [fluid-dev] Fluidsynth stops playing when stdout is piped
Date: Mon, 31 Jan 2011 07:47:19 +0000
User-agent: KMail/1.13.5 (Linux/2.6.32-2011-01-16-16.13; KDE/4.4.5; i686; ; )

On Mon, 31 Jan 2011, Matt Giuca wrote:
> > subprocess.Popen(["fluidsynth", "-sli","-a", 'alsa', "-j",
> > '/usr/share/sounds/sf2/FluidR3_GM.sf2'], stdout=subprocess.PIPE,
> > stderr=subprocess.PIPE)
> > 
> > This renders the screen output invisible, but if I have a number of
> > simultaneous connections sending commands, after a short time the audio
> > stops,
> > and when the program exits, all the missing notes are played at once!
> 
[...]
>  So when you
> disconnect, suddenly all the music will come rushing out (do they get
> played in the correct time, or do you hear all the notes literally at the
> same time?).

All at once.

> *I suspect FS is threaded in such a way that there is one thread per
> connection, hence "I leave the same instance of fluidsynth running,
> subsequent instances of my program which connect to it do not crash" --
> each connection to FluidSynth has its own thread, but per each connection,
> it will block when the buffer is full.
 
While it's true that all the connections from the first instance of my program 
will crash, connections from subsequent instances do not - provided it's still 
the same instance of fluidsynth. Maybe once a crash has occurred (i.e. the 
buffer has become full), fluidsynth stops writing to stdout?

> The solution is to make sure your Python program is always reading from
> both stdout and stderr, even if it just means discarding the output. One
> thing I noticed is that FS prints "> " prompts... maybe you are not
> reading those properly and eventually that print is blocking. If you need
> to open a file exclusively for the purpose of discarding the output (maybe
> you aren't interested in the contents of stderr, but you don't want it
> printing to your console; nor do you want it to block -- you just want to
> read and discard all the output), then you should be able to arrange it by
> passing
> stderr=open(os.path.devnull) to Popen (though I haven't tried it).
> 
Nail on the head once again. Thank you. 

(If fact I seem to get the same effect by simply calling close() on the stdout 
file, as soon as it is opened, although that worries me - where is the output 
going now?)

Regards,

John





reply via email to

[Prev in Thread] Current Thread [Next in Thread]