Use subprocess in Python
Question: I am writing a small program in Python, to record an audio WITH printing some
text at same time.

But my Print is executed until finishing of audio recording. Can you please
help me to resolve this issue?

    
    
    import picamera, subprocess, os, sys
    
    a1 = "arecord -f cd -D plughw:0 -d 10 a.wav"
    subprocess.call(a1,shell= True)
    print("Audio record is only for 10sec")
    


Answer: You're using
[`subprocess.call`](https://docs.python.org/3/library/subprocess.html#subprocess.call),
which blocks:

> Run the command described by args. **Wait for command to complete** , then
> return the returncode attribute.

You can use a
[`Popen`](https://docs.python.org/3/library/subprocess.html#popen-objects)
object, which doesn't block:

    
    
    proc = subprocess.Popen(a1.split())
    # code will proceed
    
    # use proc.communicate later on
    

Or you can have two things run separately using a
[`Thread`](https://docs.python.org/3/library/threading.html#thread-objects)
(which then spawns a process in it's own context):

    
    
    import picamera, subprocess, os, sys
    import threading
    
    def my_process():
        a1 = "arecord -f cd -D plughw:0 -d 10 a.wav"
        subprocess.call(a1,shell= True)
    thread = threading.Thread(target=my_process)
    thread.start()
    print("Audio record is only for 10sec")
    

