[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#748922: correction



Hi,

sorry, my initial snippet didnt actually call gc.collect. Calling it seems to
close the file descriptor. Here another example though, where gc.collect()
doesnt work:

--%<---------------------------------------------------
import gc, os, sys, apt_pkg
print os.listdir("/proc/self/fd/")
fd = open(sys.argv[1])
print os.listdir("/proc/self/fd/")
pkgs = list(apt_pkg.TagFile(fd))
print os.listdir("/proc/self/fd/")
fd.close()
print os.listdir("/proc/self/fd/")
del fd
print os.listdir("/proc/self/fd/")
gc.collect()
print os.listdir("/proc/self/fd/")
-->%---------------------------------------------------

yields this output:

['0', '1', '2', '3']
['0', '1', '2', '3', '4']
['0', '1', '2', '3', '4', '5']
['0', '1', '2', '3', '4']
['0', '1', '2', '3', '4']
['0', '1', '2', '3', '4']

So calling apt_pkg.TagFile with passing a fd creates yet another fd temporarily
while the original fd doesnt seem to get closed?

Investigating this further it seems that deleting "pkgs" helped and was
sufficient to end up with the original four file descriptors.

But this also means that there seems to be no way to work on the data returned
by apt_pkg.TagFile() without having a file descriptor open?

cheers, josch


Reply to: