473,410 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

IOError: [Errno 32] Broken pipe with Popen to run command

I've been trying to implement with python 2.7 a function to pass a command to cli to convert videos with ffmpeg, until now works almost great, the problem is that sometimes throws IOError: [Errno 32] Broken pipe and I'm not shure why it's happening. Can you help me with this?

This is my function to pass a command to the cli:

def _cli(cmd):
# TODO validate function
errors = False
import subprocess
try:
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdoutdata, stderrdata = p.communicate()
if p.wait() != 0:
# Handle error / raise exception
# errors used to know conversion success or not
errors = True
print stderrdata
return stdoutdata, stderrdata, errors
except OSError as e:
print 'error'
traceback.print_exc()
return e.strerror, e.strerror, errors

This is how I call it:

c = '/usr/bin/ffmpeg -hide_banner -nostats -i /home/user/original/390f8455-8657-4452-9fd9-0167d1025389.flv -c:v libx264 -c:a aac -strict -2 /home/user/original/390f8455-8657-4452-9fd9-0167d1025389.mp4'
print 'Converting command: %s' % c
stdoutdata, stderrdata, errors = _cli(c)
if errors:
print 'Converting video error'
# obj is django object
obj.convert_status = 'error'
obj.msg = stderrdata

And this is the exception:

Traceback (most recent call last):
File "/home/user/myapp/env/local/lib/python2.7/site-packages/rq/worker.py", line 799, in perform_job
rv = job.perform()
File "/home/user/myapp/env/local/lib/python2.7/site-packages/rq/job.py", line 600, in perform
self._result = self._execute()
File "/home/user/myapp/env/local/lib/python2.7/site-packages/rq/job.py", line 606, in _execute
return self.func(*self.args, **self.kwargs)
File "/home/user/myapp/cffmpeg/task.py", line 79, in convert_video
stdoutdata, stderrdata, errors = _cli(c)
File "/home/user/myapp/cffmpeg/task.py", line 216, in _cli
print stderrdata
IOError: [Errno 32] Broken pipe

Line 79 is where I call the function, and line 216 is in the function where I print the stderrdata
Apr 12 '19 #1
0 1952

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Frank de Bot | last post by:
Hi, occasionaly I find in my apache logs that fastcgi had a broken pipe error with php running as fastcgi. the logs are like this: -- > (32)Broken pipe: > FastCGI: comm with server...
0
by: Chris Jankowski | last post by:
I am trying to print an image file to a network printer and getting the following error. This is a Windows based system, using a network printer. Any ideas. Error Message: cannot print image...
1
by: Ruben | last post by:
I am reading a large text file a chunk at a time using the readlines(buffer_size) statement. I get an IOERROR ERRNO 32 Broken Pipe command when I "pipe" the output to MYSQL database using the...
2
by: Nigel King | last post by:
I have a problem with the logging module. It reports a Broken Pipe error after outputing to the log file occasionally (5%). This does not appear to happen on Mac OSX using current finked python...
0
by: nicogrubert | last post by:
Hi there I am trying to read the content of a really large text file (1GByte) and I get the following exception if I try to call readlines() on the opened textfile: IOError: Cannot allocate...
4
by: Pascal Ehlert | last post by:
I don't know if this is the right newsgroup because the question is maybe a bit linux specific so if not slap me ;-) I'm trying to send the output of a perl-script to a socket. So I'm opening a...
0
by: Marco | last post by:
Hello,every one, I meet a question: in my old script, I usually use os.popen2() to get info from standard unix(LinuX) program like ps,ifconfig... Now, I write a OO-based programme, I still use...
1
by: Christoph Krammer | last post by:
Hello everybody, I try to use an external OCR tool to convert some binary image data to text. The image is in one variable, the text should be converted to another. I use the following code: ...
11
by: 7stud | last post by:
Hi, Can someone explain what a broken pipe is? The following produces a broken pipe error: ---------- import subprocess as sub p = sub.Popen(, stdin=sub.PIPE, stdout=sub.PIPE)
2
by: Gilles Ganault | last post by:
Hello I'm trying to use urllib to download web pages with the GET method, but Python 2.5.1 on Windows turns the URL into something funny: ======== url = "amazon.fr/search/index.php?url=search"
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.