PicklingError on lambdas

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

PicklingError on lambdas

#1 Post by iichan_lolbot »

It is imposible to save game if a value was set to lambda after game start.
Tested on RenPy 6.16.5, 6.15.7 and even 6.1.0c.

Here is the minimal test case:

Code: Select all

label start:
    "You can Save here."
    $ some_check = lambda: None
    "You cannot Save here."
Error text:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "renpy/common/_layout/screen_load_save.rpym", line 17, in script
  File "renpy/common/00action_file.rpy", line 241, in python
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

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

Full traceback:
  File "C:\renpy\renpy\execution.py", line 288, in run
    node.execute()
  File "C:\renpy\renpy\ast.py", line 720, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\renpy\renpy\python.py", line 1308, in py_exec_bytecode
    exec bytecode in globals, locals
  File "renpy/common/_layout/screen_load_save.rpym", line 17, in <module>
    $ ui.interact()
  File "C:\renpy\renpy\ui.py", line 237, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "C:\renpy\renpy\display\core.py", line 1853, in interact
    repeat, rv = self.interact_core(preloads=preloads, **kwargs)
  File "C:\renpy\renpy\display\core.py", line 2406, in interact_core
    rv = root_widget.event(ev, x, y, 0)
  File "C:\renpy\renpy\display\layout.py", line 749, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\renpy\renpy\display\layout.py", line 749, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\renpy\renpy\display\layout.py", line 749, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\renpy\renpy\display\screen.py", line 319, in event
    rv = self.child.event(ev, x, y, st)
  File "C:\renpy\renpy\display\layout.py", line 749, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\renpy\renpy\display\layout.py", line 175, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\renpy\renpy\display\layout.py", line 749, in event
    rv = i.event(ev, x - xo, y - yo, cst)
  File "C:\renpy\renpy\display\layout.py", line 175, in event
    rv = d.event(ev, x - xo, y - yo, st)
  File "C:\renpy\renpy\display\behavior.py", line 636, in event
    rv = run(self.clicked)
  File "C:\renpy\renpy\display\behavior.py", line 222, in run
    return var(*args, **kwargs)
  File "renpy/common/00action_file.rpy", line 241, in __call__
    renpy.save(fn, extra_info=save_name)
  File "C:\renpy\renpy\loadsave.py", line 272, in save
    dump((roots, renpy.game.log), logf)
  File "C:\renpy\renpy\loadsave.py", line 43, in dump
    cPickle.dump(o, f, cPickle.HIGHEST_PROTOCOL)
PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Windows-post2008Server-6.2.9200
Ren'Py 6.16.5.525
test 0.0

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: PicklingError on lambdas

#2 Post by xela »

Ren'Py is using Pythons pickle/cpickle for saving, just read it's documentation and you'll understand why.
Like what we're doing? Support us at:
Image

iichan_lolbot
Veteran
Posts: 206
Joined: Tue Dec 30, 2008 9:18 am
Projects: iichan erogame
Contact:

Re: PicklingError on lambdas

#3 Post by iichan_lolbot »

Well, I understand the reasons why this does not work with cpickle. But are there are any plans to fix it in any future?
This of course is not a "batteries included" stuff, but this is surely possible to serialize a lambda and even to restore it's python source text.
Should things like this be considered as eternal "wontfix" or is there at least low-priority task to change it in some future, even years after?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: PicklingError on lambdas

#4 Post by xela »

iichan_lolbot wrote:Well, I understand the reasons why this does not work with cpickle. But are there are any plans to fix it in any future?
This of course is not a "batteries included" stuff, but this is surely possible to serialize a lambda and even to restore it's python source text.
Should things like this be considered as eternal "wontfix" or is there at least low-priority task to change it in some future, even years after?
No idea... I got this error once, figured out where it came from (I didn't know that lambda couldn't be pickled back then) and never used lambdas since (other than for sorting), can't say that it inconvenienced me in any way or form.
Like what we're doing? Support us at:
Image

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: PicklingError on lambdas

#5 Post by PyTom »

I don't think it's likely I'll add support for serializing lambdas.

Apart from my not knowing how to do it, I think it would have a lot of potential problems. Say you update a lambda in a new version of your game, but an old version is serialized in save data. That's a crash, at best.

So I'd put this in the wontfix bucket.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: No registered users