[LAD] Python assistance - threads (my favorite)

Dominic Sacré dominic.sacre at gmx.de
Fri Oct 15 07:02:09 UTC 2010


On Fri, Oct 15, 2010 at 12:04 AM, Patrick Shirkey
<pshirkey at boosthardware.com> wrote:
> In a bit of a time crunch. Can anyone tell me how to do this properly?
>
> I would like to have a threaded timer to run "cmd" after 5 seconds.
> However cmd is normally triggered like this:
>
> os.system(cmd)
>
> But there seems to be an issue with calling os.system(cmd) from
> subprocess.popen.
>
> ...
> t = threading.Timer(5.0, self.do_popen(cmd))

This line seems to be your problem. You need to give threading.Timer
the function to be called, but instead your *calling* do_popen
immediately. After five seconds the timer then tries to call the
return value of do_popen, which is None.

One possible solution would be:
t = threading.Timer(5.0, functools.partial(self.do_popen, cmd))


Dominic



More information about the Linux-audio-dev mailing list