Do you need to close a branch? (if so how)

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Feb 25 11:59:01 GMT 2009


>>>>> "Nicholas" == Nicholas Allen <nick.allen at onlinehome.de> writes:

    Nicholas> You may encounter some variation of the problem but it's hard to
    >> tell without a high level description of what your code is doing.
    >> 
    >> Are you polling the branches ? 

    Nicholas> Yes. My code looks like this:

    Nicholas>      for branch_emailer in branch_emailers.values():
    Nicholas>             branch = branch_emailer._branch

So all those _branch are kept alive right ?

Where are they coming from ? 

Did they already connect to a server ?

    Nicholas>             # Pull from parent if this is desired.
    Nicholas>             if config.pull_from_parent:
    Nicholas>                 try:
    Nicholas>                     parent_location = branch.get_parent()
            	
    Nicholas>                     if not parent_location is None:
    Nicholas>                         parent_branch = Branch.open(parent_location)

    Nicholas>                         try:
    Nicholas>                             branch.pull(parent_branch)
    Nicholas>                         finally:
    Nicholas>                             del parent_branch
    Nicholas>                 except BzrError, e:
    Nicholas>                     print >>sys.stderr, \
    Nicholas>                             'Could not pull from parent for branch %s:
    Nicholas> %s' % (branch_emailer.path, e)

    Nicholas>             # Finally send emails for this branch.
    Nicholas>             branch_emailer.send_emails()

    Nicholas>         time.sleep(config.poll_interval)

    >> 
    >> If that's the case, you may want to look at the
    >> possible_transports parameter in Branch.open.
    >> 

That was the important point. Did you look at it ?

It allows you to manage your own set of opened connections via
the transport objects.

A trivial implementation could be to do:

my_transports = []

and then

parent_branch = Branch.open(parent_location, possible_transports=my_transports)

Each new transport will then be added.

If you do that right you should have no more opened sockets than
len(my_transports).

<snip/>

    Nicholas> It shows that the sockets are still open. I've seen
    Nicholas> this with "netstat -tp" as well.

The interesting question is how many sockets do you see ? Does
that match the number of Branch.open() calls ? Does that goes
down if you use possible_transports ?

     Vincent



More information about the bazaar mailing list