Errno 9] Bad file descriptor
joblack
johannes.black at gmail.com
Wed Jul 14 07:21:54 EDT 2010
> |
> | 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.
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 ...
More information about the Python-list
mailing list