[issue3300] Extension.py not thread saft

tkruse bugs at mercurial.selenic.com
Fri Mar 2 00:36:39 CST 2012


New submission from tkruse <tkruse at willowgarage.com>:

Hi, I am writing a python script that manages several repositories, and I
ran into issues with the mercurial API. I am running 
$ hg --version
Mercurial Distributed SCM (version 1.4.3) on Ubuntu Lucid.

Every now and then I get Exceptions, when running the same command.
Exceptions look like below:

File
"/usr/local/lib/python2.6/dist-packages/vcstools-0.1.5-py2.6.egg/vcstools/hg.py",
line 260, in _get_hg_repo
    return hg.repository(ui = ui.ui(), path = path)
  File "/usr/lib/pymodules/python2.6/mercurial/hg.py", line 63, in repository
    repo = _lookup(path).instance(ui, path, create)
  File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 2151, in
instance
    return localrepository(ui, util.drop_scheme('file', path), create)
  File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 37, in
__init__
    extensions.loadall(self.ui)
  File "/usr/lib/pymodules/python2.6/mercurial/extensions.py", line 94, in
loadall
    uisetup(ui)
  File "/usr/lib/pymodules/python2.6/hgext/graphlog.py", line 354, in uisetup
    _wrapcmd(ui, 'log', commands.table, graphlog)
  File "/usr/lib/pymodules/python2.6/hgext/graphlog.py", line 364, in _wrapcmd
    entry = extensions.wrapcommand(table, cmd, graph)
  File "/usr/lib/pymodules/python2.6/mercurial/extensions.py", line 123, in
wrapcommand
    table[key] = tuple(newentry)
UnboundLocalError: local variable 'key' referenced before assignment

return hg.repository(ui = ui.ui(), path = path)
  File "/usr/lib/pymodules/python2.6/mercurial/hg.py", line 63, in repository
    repo = _lookup(path).instance(ui, path, create)
  File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 2151, in
instance
    return localrepository(ui, util.drop_scheme('file', path), create)
  File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 37, in
__init__
    extensions.loadall(self.ui)
  File "/usr/lib/pymodules/python2.6/mercurial/extensions.py", line 100, in
loadall
    extsetup(ui)
  File "/usr/lib/pymodules/python2.6/hgext/color.py", line 261, in extsetup
    _setupcmd(ui, 'qrecord', rec.cmdtable, colordiff, _diff_effects)
  File "/usr/lib/pymodules/python2.6/hgext/color.py", line 282, in _setupcmd
    entry = extensions.wrapcommand(table, cmd, nocolor)
  File "/usr/lib/pymodules/python2.6/mercurial/extensions.py", line 107, in
wrapcommand
    aliases, entry = cmdutil.findcmd(command, table)
  File "/usr/lib/pymodules/python2.6/mercurial/cmdutil.py", line 60, in findcmd
    raise error.UnknownCommand(cmd)
UnknownCommand: qrecord

In those cases I had 5 threads working on distinct (separate sibling
folders) mercurial repositories. The threads would all do:

class HackedHgUI():
    def __init__(self, ui):
        self.output = ''
        ui.write = self.write
    def write(self, output, label = None):
        self.output += output

r =  hg.repository(ui = ui.ui(), path = path)
if r is None:
  return None
fakeui = HackedHgUI(r.ui)
commands.status(ui = r.ui,
  repo = r,
  git = True,
  modified = not untracked,
  added=not untracked,
  removed=not untracked,
  deleted=not untracked)


The threads do not call any other mercurial API functions.

I had several extentions set up:
hgext.graphlog =
bookmarks=
hgext.record=
hgext.bookmarks=
hgk=
color=
hggit=
transplant=
mq=
rebase=
patchbomb=

My script runs fine about 19 times out of 20 on my machine.

I hope this is sufficient for you to confirm and fix the bug, if not already
fixed in more recent versions. I guess I will just have to serialize my
calls, as I have to rely on existing mercurial versions.

----------
messages: 19243
nosy: tkruse
priority: bug
status: unread
title: Extension.py not thread saft

____________________________________________________
Mercurial issue tracker <bugs at mercurial.selenic.com>
<http://mercurial.selenic.com/bts/issue3300>
____________________________________________________


More information about the Mercurial-devel mailing list