python-greenlet / greenlet

Lightweight in-process concurrent programming
Other
1.64k stars 247 forks source link

Greenlet does not work properly under Python 3.12 #375

Closed salabim closed 1 year ago

salabim commented 1 year ago

I am having trouble running a greenlet script that works correctly under Python 3.11 (with greenlet 3.,0,0) with Python 3.12. In order to show, I have made a Minimal Working Example:

import greenlet

def process1():
    print("process1")

def process2():
    print("process2")

def controller():
    print("controller")
    glet_process1.switch()
    glet_process2.switch()

glet_controller = greenlet.greenlet(controller)
glet_process1 = greenlet.greenlet(process1,parent=glet_controller)
glet_process2 = greenlet.greenlet(process2,parent=glet_controller)

glet_controller.switch()
print("finished")

Under 3.11 (and below) this prints out:

controller
process1
process2
finished

, but under Python 3.12.0a2, the program stops in process1:

controller
process1

and never switched back to the controller (and process2).

I hope someone can fix this bug as it prevents me from publishing my simulation package salabim for 3.12.

salabim commented 1 year ago

I just installed the final release version of Python 3.12(.0) and greenlet works correctly, now! Sorry for this false alarm.