Commit bd14f3a6 authored by Arnaud Fontaine's avatar Arnaud Fontaine

PortalTransforms: subprocesstransform: Make sure that the NamedTemporaryFile is closed.

parent 225fc819
...@@ -147,24 +147,24 @@ class subprocesstransform: ...@@ -147,24 +147,24 @@ class subprocesstransform:
def convert(self, data, cache, **kwargs): def convert(self, data, cache, **kwargs):
command = "%s %s" % (self.binary, self.binaryArgs) command = "%s %s" % (self.binary, self.binaryArgs)
stdin_file = PIPE
try:
if not self.useStdin:
stdin_file = tempfile.NamedTemporaryFile()
stdin_file.write( data)
stdin_file.seek(0)
command = command % {'infile': stdin_file.name} # apply tmp name to command
data = None
argument_list = shlex.split(command)
process = Popen(argument_list, stdin=stdin_file, stdout=PIPE,
stderr=PIPE, close_fds=True)
data_out, data_err = process.communicate(input=data)
if process.returncode:
raise OSError, data_err
cache.setData(data_out)
return cache
if not self.useStdin: finally:
tempfile_object = tempfile.NamedTemporaryFile() if isinstance(stdin_file, file):
tmpname = tempfile_object.name stdin_file.close()
tempfile_object.write( data)
tempfile_object.seek(0)
command = command % {'infile': tmpname} # apply tmp name to command
argument_list = shlex.split(command)
if self.useStdin:
process = Popen(argument_list, stdin=tempfile_object, stdout=PIPE,
stderr=PIPE, close_fds=True)
data_out, data_err = process.communicate()
tempfile_object.close()
else:
process = Popen(argument_list, stdin=PIPE, stdout=PIPE,
stderr=PIPE, close_fds=True)
data_out, data_err = process.communicate(input=data)
if process.returncode:
raise OSError, data_err
cache.setData(data_out)
return cache
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment