Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
pypy
pypy
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 594
    • Issues 594
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 10
    • Merge Requests 10
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

This instance will be upgraded to the latest Heptapod 0.20rc on 2021-02-26 at 11:00 UTC+1

  • PyPy
  • pypypypy
  • Issues
  • #3162

Closed
Open
Opened Jan 29, 2020 by Bitbucket Importer@bitbucket_importerMaintainer

GreenletExit not thrown when a greenlet is garbage-collected

Created originally on Bitbucket by antocuni (Antonio Cuni)

import greenlet
import gc

class A(object):
	def __del__(self):
		print 'A.__del__'

def g1():
	try:
		print 'g1: begin'
		a = A()
		print 'g1: switching'
		MAIN.switch()
	except greenlet.GreenletExit:
		print 'g1: GreenletExit'
	finally:
		print 'g1: finally'

def main():
	global MAIN
	MAIN = greenlet.getcurrent()
	greenlet.greenlet(g1).switch()
	gc.collect()

main()

These are the results on CPython and PyPy; A.__del__ is used just to show that the greenlet is actually garbage collected.

$ python green.py 
g1: begin
g1: switching
g1: GreenletExit
g1: finally
A.__del__

$ pypy green.py 
g1: begin
g1: switching
A.__del__

‌

The following patch seems to be enough to fix the problem; however, since it’s a good practice to be very careful when dealing with greenlets and continuelets, I’d like some feeback before committing it:

diff --git a/lib_pypy/greenlet.py b/lib_pypy/greenlet.py
--- a/lib_pypy/greenlet.py
+++ b/lib_pypy/greenlet.py
@@ -47,6 +47,9 @@
         if parent is not None:
             self.parent = parent
 
+    def __del__(self):
+        self.throw()
+
     def switch(self, *args, **kwds):
         "Switch execution to this greenlet, optionally passing the values "
         "given as argument(s).  Returns the value passed when switching back."

‌

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: pypy/pypy#3162