Peter's Blog

Redefining the Impossible

TurboGears hang under Windows


Had turbogears hanging while debugging under WingIDE but working fine from the command line. One nice thing about using a decent debugger like WingIDE is I can press the pause button and see what it is doing when it appears to be hung.

It turns out it was in a kid function called 'relativize' that looks like this:

   1  def relativize(self, file, path):
   2      from os.path import normpath, join, dirname, abspath, split, sep
   3      head, tail = (dirname(abspath(file)), '')
   4      parts = path.split(sep)
   5      paths = self.paths
   6      while 1:
   7          if head in paths or head == '/':
   8              return join(*parts)
   9          head, tail = split(head)
  10          parts.insert(0, tail)

It is trying to turn an absolute path into a relative path. The code was stuck in the while loop because 'head' was never 'in paths' or == '/'. The '/' would never match as this was windows and uses '\' as a file seperator, 'in paths' was broken because the path was in there a 'c:\Project\Path' but head was equal to 'C:\Project\Path': different capitalisation on the C. Tracing back, the upper case version was being returned by os.getcwd, the lower case version by the python package module. To cut a long story short, I had set the initial debug directory in WingIDE to 'c:\Project\Path' with a lower case c and changing it to an upper case c in Wing fixed the problem.

Conclusion: Must bear in mind that kid may be flaky on Windows.

UPDATE: it broke again sad Resorted to fixing kid thusly:

   1  def relativize(self, file, path):
   2      from os.path import normpath, join, dirname, abspath, split, sep
   3      from os.path import normcase  # pcw
   4      file = normcase( file)  # pcw
   5      head, tail = (dirname(abspath(file)), '')
   6      parts = path.split(sep)
   7      paths = [normcase( strPath) for strPath in self.paths]  # pcw
   8      while 1:
   9          if head in paths or head == '\\':
  10              return join(*parts)
  11          head, tail = split(head)
  12          parts.insert(0, tail)

Filed under: kid python turbogears

Have Your Say

I welcome constructive comments or questions but I reserve the right to delete any comments that displease me.

Who are you?

(Optional) If you enter an email address here I might email you back. Your email address will not be sold to spammers or shown anywhere

What do you have to say?