Skip to content

Scene-Caching w/ "-" as filename bug : Cannot use Updaters. #348

@Aathish04

Description

@Aathish04

Consider the following test script:

class Test(Scene):
        def construct(self):
                v = ValueTracker(10)
                a = Integer().add_updater(lambda m:m.set_value(v.get_value()))
                self.add(a)
                self.play(v.set_value,100)

Rendering this by saving it as a file, then rendering it will work. However, if you render the same test script by inputting it directly into STDIN, which you can do by providing - as the filename, then the render will fail with the following traceback:

Traceback (most recent call last):
  File "/Users/aathishs/Python/ManimEnv/manim/manim/__main__.py", line 168, in main
    scene = SceneClass()
  File "/Users/aathishs/Python/ManimEnv/manim/manim/scene/scene.py", line 77, in __init__
    self.construct()
  File "<string>", line 7, in construct
  File "/Users/aathishs/Python/ManimEnv/manim/manim/scene/scene.py", line 802, in wrapper
    hash_play = get_hash_from_play_call(
  File "/Users/aathishs/Python/ManimEnv/manim/manim/utils/hashing.py", line 146, in get_hash_from_play_call
    current_mobjects_list_json = [
  File "/Users/aathishs/Python/ManimEnv/manim/manim/utils/hashing.py", line 147, in <listcomp>
    get_json(x) for x in sorted(current_mobjects_list, key=lambda obj: str(obj))
  File "/Users/aathishs/Python/ManimEnv/manim/manim/utils/hashing.py", line 98, in get_json
    return json.dumps(obj, cls=CustomEncoder)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/Users/aathishs/Python/ManimEnv/manim/manim/utils/hashing.py", line 82, in encode
    return super().encode(self._encode_dict(obj))
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Users/aathishs/Python/ManimEnv/manim/manim/utils/hashing.py", line 40, in default
    return {"code": inspect.getsource(obj), "nonlocals": cvardict}
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 985, in getsource
    lines, lnum = getsourcelines(object)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 967, in getsourcelines
    lines, lnum = findsource(object)
  File "/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/inspect.py", line 798, in findsource
    raise OSError('could not get source code')
OSError: could not get source code

cc @huguesdevimeux

Metadata

Metadata

Labels

pr:bugfixBug fix for use in PRs solving a specific issue:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions