Why is this Popen with threading not working?









up vote
0
down vote

favorite












I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.



My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.



Here is the main part of the code:



def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()

def buttonClick(v0,v1,v2,v3):

#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()

#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)


Why is my thread not working?










share|improve this question























  • Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
    – stovfl
    Nov 6 at 15:10














up vote
0
down vote

favorite












I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.



My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.



Here is the main part of the code:



def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()

def buttonClick(v0,v1,v2,v3):

#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()

#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)


Why is my thread not working?










share|improve this question























  • Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
    – stovfl
    Nov 6 at 15:10












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.



My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.



Here is the main part of the code:



def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()

def buttonClick(v0,v1,v2,v3):

#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()

#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)


Why is my thread not working?










share|improve this question















I wrote a little tkinter GUI to handle 4 inputs to ffmpeg. Since the subprocess will take some time i want to status the process. Therefore I use threading so tkinter doesn't freeze while the subprocess is executed.



My problem is that with threading the ffmpeg command outputs the destination file with 0kb and nothing is anymore written to the file. If I use my function without threading everything works, but the GUI is freezing.



Here is the main part of the code:



def ffmpeg(v0,v1,v2,v3):
cmd = [ path+'ffmpeg.exe',"-y","-i",v0,"-i",v1,"-i",v2,'-i',v3,'-filter_complex',"[0:v][1:v]hstack[top];[2:v][3:v]hstack[bottom];[top][bottom]vstack,format=yuv420p[v]",'-map',"[v]","out.mp4"]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
inpu = process.stderr.readline()
if output == b'' and process.poll() is not None:
break
if output:
print(output.strip()) # HERE i will insert into tkinter textfield
rc = process.poll()

def buttonClick(v0,v1,v2,v3):

#ffmpeg(v0,v1,v2,v3) # This line works
t = threading.Thread(target=ffmpeg,args=(v0,v1,v2,v3,)) #This doesn't work
t.start()
#t.join()

#tkvar list elements are absolute paths to the videofiles
submitButton = Button(mainframe, text="Process Video", command=lambda: buttonClick(tkvar[0].get(),tkvar[1].get(),tkvar[2].get(),tkvar[3].get()))
submitButton.grid(row = 7, column =3)


Why is my thread not working?







python multithreading tkinter ffmpeg subprocess






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 at 10:37

























asked Nov 6 at 10:27









user2853437

192214




192214











  • Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
    – stovfl
    Nov 6 at 15:10
















  • Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
    – stovfl
    Nov 6 at 15:10















Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
– stovfl
Nov 6 at 15:10




Move this line inpu = process.stderr.readline(), outside the while. It blocks untils the process finished.
– stovfl
Nov 6 at 15:10












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










The problem was that
process.stdout.readline()
Is always empty since ffmpeg writes always everything to stderr.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170019%2fwhy-is-this-popen-with-threading-not-working%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    The problem was that
    process.stdout.readline()
    Is always empty since ffmpeg writes always everything to stderr.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      The problem was that
      process.stdout.readline()
      Is always empty since ffmpeg writes always everything to stderr.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        The problem was that
        process.stdout.readline()
        Is always empty since ffmpeg writes always everything to stderr.






        share|improve this answer












        The problem was that
        process.stdout.readline()
        Is always empty since ffmpeg writes always everything to stderr.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 16:30









        user2853437

        192214




        192214



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53170019%2fwhy-is-this-popen-with-threading-not-working%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            政党