On 07/14/2010 01:21 PM, joblack wrote:
>> |
>> | Starting point:
>> | ...
>> |         self.status['text'] = 'Processing ...'
>> |         try:
>> |             cli_main(argv)
>> |         except Exception, e:
>> |             self.status['text'] = 'Error: ' + str(e)
>> |             return
>> | ...
>> | cli_main:
>> |
>> |     keypath, inpath, outpath = argv[1:]
>> | ...
>> |     with open(inpath, 'rb') as inf:
>> |         serializer = PDFSerializer(inf, keypath)
>> |         with open(outpath, 'wb') as outf:
>> |             filenr = outf.fileno()
>> |             serializer.dump(outf)
>> |     return 0
>> |
>> | PDFSerializer.dump:
>> |
>> |     def dump(self, outf):
>> |         self.outf = outf
>> | ...
>>
>> See that you set serializer.outf to the outf you open in cli_main?
>> Any attempt to use serializer _after_ exiting the "with open(outpath,
>> 'wb') as outf" will use serializer.outf, but the outf is now closed.
>> And thus itsfiledescriptoris invalid.
> 
> Okay, I changed it to a try: ... finally: block where I open the file
> and in finally I close it. Nothing has changed. The error still
> occures.

Where does the error occur? If Cameron is right, it occurs somewhere
completely different, when serializer.dump() is already long done, when
some unsuspecting fool tries to do something with serializer.outf (such
as closing it)

> 
> Doesn't the
> 
> with open(outpath, 'wb') as outf:
> 
> clause has to wait until the pdfserialiser.dump method has finished
> anyway? IMHO it can't just call it and immediately close it.
> 
> At least the try: finally: construct should work? Or does it the same
> (call the method and immediately jump to the finally close)?
> 
> Would it work if I would write:
> 
> with closing(outpath, 'wb') as outf: ?
> 
> I'm a little bit confused about Python's strange processing ...

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to