[Solved] ValueError: generator already executing on exit (Ren'py doesn't seem to like deepcopy)

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

[Solved] ValueError: generator already executing on exit (Ren'py doesn't seem to like deepcopy)

#1 Post by kivik »

A bit of a strange one and I struggle to reproduce this, but when I use CMD-Q to quit my game (pre-compiled), I sometimes get the following message:

Code: Select all

ValueError: generator already executing
It started happening since I've hooked my loops together, and it doesn't happen all the time. Google is suggesting that it's a multi-thread issue, and I can only assume it's because I've got some screens in a loop. I'm not super worried about it since it seems to only happen when I use the CMD-Q shortcut to quit, using the Esc route > in game Quit button doesn't seem to trigger it.

As my code is getting pretty large I don't know how easy it would be to trace it, but I'm happy to post the codebase to PyTom if it helps. My pseudo code follows the lines of:

Code: Select all

label start:
    show screen npcdetails
    while True:
        advance_time()
        if newday:
            call daily_schedule_label
        do_more_stuff()
    return

label daily_schedule_label:
    $ loop = True
    while loop:
        call screen schedule
        if _return == "finished":
            loop = False
    set_schedule_stuff()
    return
Last edited by kivik on Wed Apr 18, 2018 7:22 pm, edited 2 times in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2401
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: ValueError: generator already executing on exit

#2 Post by Ocelot »

Is that the only message you have? Usually if it is an exception from inside RenPy, you get a whole stacktrace and a page with additional information.
< < insert Rick Cook quote here > >

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: ValueError: generator already executing on exit

#3 Post by kivik »

I never saw the copy button before, thought I'd have to type all of it up!

Here it is below.

I didn't have this problem when I was purely testing the call screen schedule before, but maybe I've changed some code that I didn't remember.

The screen also calls additional screens in loops as well, I've pasted the code for the screens further below.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 14, in script call
    call setSchedule(npc_catherine)
  File "game/script.rpy", line 62, in script
    call screen schedule(character)
  File "renpy/common/000statements.rpy", line 485, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
ValueError: generator already executing

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 14, in script call
    call setSchedule(npc_catherine)
  File "game/script.rpy", line 62, in script
    call screen schedule(character)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/ast.py", line 1801, in execute
    self.call("execute")
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/ast.py", line 1789, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/statements.py", line 169, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 485, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/exports.py", line 2655, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/ui.py", line 287, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/display/core.py", line 2624, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/display/core.py", line 3224, in interact_core
    self.idle_frame(can_block, expensive)
  File "/Users/dev/Documents/renpy-6.99.14.1-sdk/renpy/display/core.py", line 2720, in idle_frame
    result = self.prediction_coroutine.send(expensive)
ValueError: generator already executing

Darwin-17.4.0-x86_64-i386-64bit
Ren'Py 6.99.14.1.3218
Due Process Alpha 0.1
Sat Apr  7 12:27:22 2018
Screen code:

Code: Select all

init 10:
    python:
        screen_meal_description = ""
        screen_task_description = ""

screen schedule(character):
    $ padding = 20
    frame:
        yalign 1.0
        xalign 1.0
        top_padding padding
        bottom_padding padding
        left_padding padding
        right_padding padding
        vbox:
            spacing 20
            label character.name.title():
                xalign 0.5
            hbox:
                spacing 10
                frame:
                    xminimum 300
                    xmaximum 300
                    vbox:
                        label "Breakfast"
                        textbutton scheduleOptions["meals"]["breakfast"] action [Call("scheduleMeal", "breakfast", character), Return(True)]
                        label "Task"
                        textbutton scheduleOptions["tasks"]["breakfast"] action [Call("scheduleTask", "breakfast", character), Return(True)]
                frame:
                    xminimum 300
                    xmaximum 300
                    vbox:
                        label "Lunch"
                        textbutton scheduleOptions["meals"]["lunch"] action [Call("scheduleMeal", "lunch", character), Return(True)]
                        label "Task"
                        textbutton scheduleOptions["tasks"]["lunch"] action [Call("scheduleTask", "lunch", character), Return(True)]
                frame:
                    xminimum 300
                    xmaximum 300
                    vbox:
                        label "Dinner"
                        textbutton scheduleOptions["meals"]["dinner"] action [Call("scheduleMeal", "dinner", character), Return(True)]
                        label "Task"
                        textbutton scheduleOptions["tasks"]["dinner"] action [Call("scheduleTask", "dinner", character), Return(True)]
            textbutton "Finished":
                xalign 0.5
                action Return("finished")

label scheduleMeal(meal, character):
    $ screen_meal_description = ""
    $ smloop = True
    while smloop:
        call screen scheduleMeal(meal, character)
        if _return != None:
            $ scheduleOptions["meals"][meal] = _return
            $ smloop = False
    return

screen scheduleMeal(meal, character):
    $ padding = 20
    frame:
        yalign 0.5
        xalign 0.5
        top_padding padding
        bottom_padding padding
        left_padding padding
        right_padding padding
        xminimum 900
        xmaximum 900
        vbox:
            spacing 20
            label meal.title() + " for [character.name]"
            hbox:
                spacing 20
                frame:
                    vbox:
                        for meal in meals.getMealsByType(meal):
                            textbutton meal.name:
                                hovered [SetVariable("screen_meal_description", meal.description)]
                                action Return(meal.name)
                text screen_meal_description

label scheduleTask(meal, character):
    $ screen_task_description = ""
    $ stloop = True
    while stloop:
        call screen scheduleTask(meal, character)
        if _return != None:
            $ scheduleOptions["tasks"][meal] = _return
            $ stloop = False
    return

screen scheduleTask(meal, character):
    $ padding = 20
    frame:
        yalign 0.5
        xalign 0.5
        top_padding padding
        bottom_padding padding
        left_padding padding
        right_padding padding
        xminimum 900
        xmaximum 900
        vbox:
            spacing 20
            label meal.title() + " for [character.name]"
            hbox:
                spacing 20
                frame:
                    vbox:
                        for task in tasks.getTasksByMeal(meal):
                            textbutton task.name:
                                hovered [SetVariable("screen_task_description", task.description)]
                                action Return(task.name)
                text screen_task_description

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: ValueError: generator already executing on exit

#4 Post by kivik »

Just wondering if anyone has any clue on this by any chance? PyTom?

I think this is caused by me calling screens after calling screens which I read somewhere during my search that it causes context problems.

My game loop looks something like this:

Code: Select all

while loop:
    call screen schedulescreen
    if _return == "done":
        loop = False

...

screen schedulescreen:
    textbutton "set meal" action [Call("schedulemeal"), Return(True)]


label schedulemeal:
    call screen schedule_meal
    $ setmeal(_return)
    return

screen schedule_meal:
    textbutton "pancakes" action Return("pancakes")
But I'm really confused as to how I should be doing a screen that loads another screen any other way.

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: ValueError: generator already executing on exit

#5 Post by Alex »

What if just show the modal screen instead of calling one?
(just in case https://www.renpy.org/doc/html/screens. ... -statement)

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: ValueError: generator already executing on exit

#6 Post by kivik »

Ok I think I've found out what's been causing the error.

One thing I haven't done whilst testing was to save the game, and I started noticing that the game crashes everytime I quit now, when it tries to autosave. It just kinda freezes instead of throwing an error and I had to force quit.

Out of curiosity I manually saved the game during testing and this time it threw an error message, something about COPY it wasn't happy with - and it clued me into something unusual that I've done with this game:

I've imported the deepcopy function and used it, and I realised deepcopy was used as part of my schedule screen calling, and the error must have started around the time I found and used that function.

After removing the deepcopy line I've not encountered this error on quit, so I feel confident that it is the reason for the error in the first place. I just need reconsider my code to see whether I really need deepcopy - I just wanted to make sure I wasn't copying a pointer to an object when I did it...

Post Reply

Who is online

Users browsing this forum: No registered users