Edgewall Software

Ticket #5339 (closed defect: fixed)

Opened 20 months ago

Last modified 9 months ago

GeneratorExit thrown in trac/wiki/macros.py

Reported by: njg@… Owned by: thatch
Priority: normal Milestone: 0.10.5
Component: wiki system Version: 0.10.4
Severity: normal Keywords: python25
Cc: dluke@…

Description (last modified by cboos) (diff)

Class UserMacroProvider throws an annoying error in method get_macros (with python 2.5). Simple (2 line) fix, where the GeneratorExit exception is ignored.

snippet from trac/wiki/macros.py

    def get_macros(self):
        found = []
        for path in (self.env_macros, self.site_macros):
            if not os.path.exists(path):
                continue
            for filename in [filename for filename in os.listdir(path)
                             if filename.lower().endswith('.py')
                             and not filename.startswith('__')]:
                try:
                    module = self._load_macro(filename[:-3])
                    name = module.__name__
                    if name in found:
                        continue
                    found.append(name)
                    yield name
                except GeneratorExit:
                    pass
                except Exception, e:
                    self.log.error('Failed to load wiki macro %s (%s)',
                                   filename, e, exc_info=True)

Attachments

Change History

  Changed 16 months ago by anonymous

I can confirm this on 0.10.4. This ticket has been fallow for 4 months - is it likely to be fixed?

follow-up: ↓ 3   Changed 16 months ago by cboos

  • keywords python25 verify added; generator GeneratorExit yield exception removed
  • summary changed from trac/wiki/macros.py and python 2.5 to GeneratorExit thrown in trac/wiki/macros.py
  • description modified (diff)
  • milestone set to 0.10.5

Sorry, this report went unnoticed.

in reply to: ↑ 2   Changed 16 months ago by njg

Replying to cboos:

Sorry, this report went unnoticed.

May have been my fault... my first (official) bug report ever! I'm glad it turns out not to have been a waste of time/effort.

I still use trac, though I haven't given it much scrutiny now that it/s up and running stably on my server. I'll be pleased to participate in the trac community, though.

  Changed 15 months ago by anonymous

My reading suggests this is likely caused by Python 2.5's close function for generators. If Trac isn't calling this itself then I guess it must be the garbage collector. The correct behaviour seems to be to not catch the exception:

--- trac/wiki/macros.py 2007-04-20 14:41:49.000000000 +0100
+++ trac/wiki/macros.py 2007-10-03 17:24:41.347073000 +0100
@@ -446,6 +446,9 @@
                         continue
                     found.append(name)
                     yield name
+                except GeneratorExit:
+                    # never catch GeneratorExit
+                    raise
                 except Exception, e:
                     self.log.error('Failed to load wiki macro %s (%s)',
                                    filename, e, exc_info=True)

From a google search of the docs:

close()

Raises a GeneratorExit at the point where the generator function was paused. If the generator function then raises StopIteration (by exiting normally, or due to already being closed) or GeneratorExit (by not catching the exception), close returns to its caller. If the generator yields a value, a RuntimeError is raised. If the generator raises any other exception, it is propagated to the caller. close does nothing if the generator has already exited due to an exception or normal exit.

I hope that helps.

  Changed 11 months ago by osimons

#4026 closed as duplicate.

  Changed 11 months ago by cboos

  • priority changed from low to normal
  • milestone changed from 0.10.5 to 0.11.1

  Changed 10 months ago by dluke@…

  • cc dluke@… added

  Changed 9 months ago by thatch

  • status changed from new to assigned
  • severity changed from minor to normal
  • owner changed from cboos to thatch
  • version changed from 0.10-stable to 0.10.4
  • milestone changed from 0.11.1 to 0.10.5
  • keywords verify removed

This error kept phaidros on IRC from being able to view any of the TracGuide pages. This seems to happen mainly to Ubuntu Gutsy users. I'm not able to reproduce this issue (though I can reproduce #4026) on my 64-bit machine, and the patch silences those as well.

phaidros confirms that the patch above makes the TracGuide pages viewable once again. Here is the error, for posterity:

2008-04-03 23:49:18,919 Trac[macros] ERROR: Failed to load wiki macro TracGuideToc.py ()
Traceback (most recent call last):
  File "/var/lib/python-support/python2.5/trac/wiki/macros.py", line 448, in get_macros
    yield name
GeneratorExit
2008-04-03 23:49:18,920 Trac[formatter] DEBUG: Executing Wiki macro TracGuideToc by provider <trac.wiki.macros.UserMacroProvider object at 0x85a858c>

This bug is filed downstream as https://bugs.launchpad.net/ubuntu/+source/trac/+bug/199306

  Changed 9 months ago by thatch

  • status changed from assigned to closed
  • resolution set to fixed

Should be solved by r6801

Add/Change #5339 (GeneratorExit thrown in trac/wiki/macros.py)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from thatch. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.