dispatchrun / dispatch-py

Python package to develop applications with Dispatch.
https://pypi.org/project/dispatch-py/
Apache License 2.0
54 stars 3 forks source link

Cannot create durable nested function #117

Open pelletier opened 6 months ago

pelletier commented 6 months ago

Reproduction:

import httpx
from fastapi import FastAPI

from dispatch.fastapi import Dispatch

app = FastAPI()

dispatch = Dispatch(app)

def main():
    @dispatch.function
    async def sub1():
        return 42

    @dispatch.function
    async def main():
        await sub1()

    @app.get("/")
    def root():
        main.dispatch()
        return "OK"

main()

This results in the following error:


[DURABLE] Serializing DurableCoroutine(main.<locals>.main):
function = main.<locals>.main (/Users/thomas/src/github.com/stealthrocket/dispatch-py/bug_reproduction.py:16)
code hash = sha256:8188f279bc2ec3e905fc0e115713b13c1e5b8f571f046f081cf8ac4aed9585a8
args = ()
kwargs = {}
wrapped coroutine = None
frame state = -1
IP = 28
SP = 2
stack[0] = <cell at 0x10536dc60: Function object at 0x1053794e0>
stack[1] = DurableCoroutineWrapper(Function._call_async)

unexpected exception occurred during coroutine scheduling
Traceback (most recent call last):
  File "/Users/thomas/.venv/dispatch-tester/lib/python3.12/site-packages/dispatch/scheduler.py", line 215, in run
    return self._run(input)
           ^^^^^^^^^^^^^^^^
  File "/Users/thomas/.venv/dispatch-tester/lib/python3.12/site-packages/dispatch/scheduler.py", line 424, in _run
    serialized_state = pickle.dumps(state)
                       ^^^^^^^^^^^^^^^^^^^
TypeError: cannot pickle 'cell' object
INFO:     2600:1f13:6ac:6005::3b0:0 - "POST /dispatch.sdk.v1.FunctionService/Run HTTP/1.1" 200 OK

Python build:

Python 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin