Edgewall Software
Modify

Opened 18 years ago

Closed 17 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@… Branch:
Release Notes:
API Changes:
Internal 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):
                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 (0)

Change History (9)

comment:1 by anonymous, 17 years ago

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

comment:2 by Christian Boos, 17 years ago

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.

in reply to:  2 comment:3 by njg, 17 years ago

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 by anonymous, 17 years ago

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.

comment:5 by osimons, 17 years ago

#4026 closed as duplicate.

comment:6 by Christian Boos, 17 years ago

Milestone: 0.10.50.11.1
Priority: lownormal

comment:7 by dluke@…, 17 years ago

Cc: dluke@… added

comment:8 by Tim Hatch, 17 years ago

Keywords: verify removed
Milestone: 0.11.10.10.5
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
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

comment:9 by Tim Hatch, 17 years ago

Resolution: fixed
Status: assignedclosed

Should be solved by r6801

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Tim Hatch.
The resolution will be deleted. Next status will be 'reopened'.
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.