console breaks when running in parallel
See original GitHub issueI am calling the following code inside the job of an pool.imap_unordered
:
data, _ = (ffmpeg
.input(filename)
.output('pipe:', format=format, acodec=acodec, ac=ac, ar=sr)
.run(capture_stdout=True, capture_stderr=True))
in order to load a lot of audio in parallel. It seems to work correctly, but when it’s done running I can’t type in the console anymore. Or rather, the text I type does not appear, but when I hit return the commands are still executed.
If I run the script inside screen
and then exit the screen, the original console works.
Is there another way that I should be running ffmpeg-python when using multiprocessing?
Looking at this issue https://askubuntu.com/questions/171449/shell-does-not-show-typed-in-commands-reset-works-but-what-happened my situation matches it very closely. Before I run the script the result of stty --all
is:
speed 9600 baud; rows 33; columns 197; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O;
min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
and after it is:
speed 9600 baud; rows 33; columns 197; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O;
min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig -icanon -iexten -echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
echo
is one of the options that switches from true to false. But I can’t find what in the ffmpeg-python library causes this.
Previously I had written my own wrapper to ffmpeg https://github.com/kylemcdonald/python-utils/blob/master/ffmpeg_load_audio.py I didn’t notice this problem before. But I just did some more testing and it has the same bug. Which means it’s something pretty basic about running Popen in threads.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Hi, Just wanted to say that adding
'-nostdin'
to.global_args()
in reader processes fixed the issue with terminal for me.Hi 👋I’m back again.
I found an example that doesn’t use any threads outside the library, just
run_async
. I think this could give a clue of what’s going on:This code stacks two videos side by side (you wouldn’t want to do it this way of course, it’s just an example). The snippet above works. But if you move this line down:
So it appear after the
break
fromnot in2_bytes
, then the terminal gets messed up. Even though we knowprocess2.stdout.read
is going to returnNone
, we need to call it for it to properly make the terminal go back to normal.If you have some script that is too complicated to figure out where this is happening, you can also add this to the end of your script:
And it will return the terminal to normal even if there’s some async code that has messed it up somehow.