Edgewall Software

Opened 10 years ago

Closed 9 years ago

#5339 closed defect (fixed)

GeneratorExit thrown in trac/wiki/macros.py

Reported by: njg@… Owned by: Tim Hatch
Priority: normal Milestone: 0.10.5
Component: wiki system Version: 0.10.4
Severity: normal Keywords: python25
Cc: dluke@…
Release Notes:
API Changes:

Description (last modified by Christian Boos)

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):
            for filename in [filename for filename in os.listdir(path)
                             if filename.lower().endswith('.py')
                             and not filename.startswith('__')]:
                    module = self._load_macro(filename[:-3])
                    name = module.__name__
                    if name in found:
                    yield name
                except GeneratorExit:
                except Exception, e:
                    self.log.error('Failed to load wiki macro %s (%s)',
                                   filename, e, exc_info=True)

Attachments (0)

Change History (9)

comment:1 Changed 10 years 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?

comment:2 Changed 10 years ago by Christian Boos

Description: modified (diff)
Keywords: python25 verify added; generator GeneratorExit yield exception removed
Milestone: 0.10.5
Summary: trac/wiki/macros.py and python 2.5GeneratorExit thrown in trac/wiki/macros.py

Sorry, this report went unnoticed.

comment:3 in reply to:  2 Changed 10 years 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.

comment:4 Changed 10 years 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 @@
                     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:


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.

comment:5 Changed 10 years ago by osimons

#4026 closed as duplicate.

comment:6 Changed 10 years ago by Christian Boos

Priority: lownormal

comment:7 Changed 10 years ago by dluke@…

Cc: dluke@… added

comment:8 Changed 9 years ago by Tim Hatch

Keywords: verify removed
Owner: changed from Christian Boos to Tim Hatch
Severity: minornormal
Status: newassigned
Version: 0.10-stable0.10.4

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
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

comment:9 Changed 9 years ago by Tim Hatch

Resolution: fixed
Status: assignedclosed

Should be solved by r6801

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Tim Hatch.
The resolution will be deleted.
to The owner will be changed from Tim Hatch to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .

Note: See TracTickets for help on using tickets.