Skip to content

Instantly share code, notes, and snippets.

@nicholas-gh
Created May 7, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholas-gh/960478 to your computer and use it in GitHub Desktop.
Save nicholas-gh/960478 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import time
import gc
import itertools
from svn import fs, repos, core, delta
# demonstrate leaking file descriptors
# with python 2.4 / subversion-python-1.6.9
# python 2.4 / subversion-1.6.12-0.3logica
# python 2.6.6 / python-subversion 1.6.9dfsg-1
# sample output:
# pid 21413
# youngest 4
# python objects 13018
# fds 7
# youngest 5
# python objects 13018
# fds 8
# youngest 6
# python objects 13018
# fds 9
# youngest 7
# python objects 13018
# fds 10
# youngest 8
# python objects 13018
# fds 11
# youngest 9
# python objects 13018
# fds 12
# before using, run "svnadmin create /tmp/fresh"
core.apr_initialize()
print "pid %d" % os.getpid()
open('/tmp/content', 'w').write("content")
while True:
time.sleep(1)
repo = repos.open('/tmp/fresh')
fs_ptr = repos.fs(repo)
youngest = fs.youngest_rev(fs_ptr)
print "youngest", youngest
txn = repos.fs_begin_txn_for_commit(repo, youngest, "user", "log")
troot = fs.txn_root(txn)
if fs.check_path(troot, "content.txt") == core.svn_node_none:
print "Creating new file"
fs.make_file(troot, "content.txt")
handler, baton = fs.apply_textdelta(troot, "content.txt", None, None)
f = open('/tmp/content')
# this works fine, but means we have the whole file in memory
#delta.svn_txdelta_send_string(f.read(), handler, baton)
delta.svn_txdelta_send_stream(f, handler, baton) # this appears to leak fd for f
# I guess because svn_swig_py_make_stream() does
# svn_stream_create() but we never do svn_stream_close(), because
# Python doesn't get to see the svn_stream_t ?
# http://svn.apache.org/viewvc?view=revision&revision=852660
# http://svn.apache.org/viewvc?view=revision&revision=861447
repos.fs_commit_txn(repo, txn)
gc.collect()
print "python objects", len(gc.get_objects())
print "fds", len(os.listdir("/proc/%d/fd" % os.getpid()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment