Skip to content

prevent infinite recursion with linking to current greenthread#1

Merged
temoto merged 1 commit intoeventlet:masterfrom
edwardgeorge:greenthread-link-fix
Dec 13, 2012
Merged

prevent infinite recursion with linking to current greenthread#1
temoto merged 1 commit intoeventlet:masterfrom
edwardgeorge:greenthread-link-fix

Conversation

@edwardgeorge
Copy link
Copy Markdown
Contributor

@temoto temoto merged this pull request into eventlet:master Dec 13, 2012
@temoto
Copy link
Copy Markdown
Member

temoto commented Dec 13, 2012

Thank you very much. 👍

Just out of curiosity, could you show an example where one would link inside linked function? Sounds like yo-dawg trolling. :)

@edwardgeorge
Copy link
Copy Markdown
Contributor Author

there's an example in the linked issue report on bitbucket. it probably doesn't make much sense normally to link within a linked function but sometimes things can have an unexpected side-effect that links something to the current greenthread, which is what happens in the given example: eventlet.green.threading.getcurrent links a cleanup function to the current greenthread the first time it's seen.

A copy of that code example is included below:

import eventlet
from eventlet import patcher

logging = patcher.import_patched('logging')
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

def do_nothing():
    return

def log_exit(gt):
    logger.debug('exited!')

g = eventlet.spawn(do_nothing)
g.link(log_exit)
g.wait()

I think logging in a linked function is not an unexpected pattern. this results in:

RuntimeError: maximum recursion depth exceeded

@temoto
Copy link
Copy Markdown
Member

temoto commented Dec 16, 2012

Thanks, indeed this looks like a reasonable pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants