h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
4.01k stars 328 forks source link

Cythonized project throws an error "ValueError(f"@on function '{func_name}' must be async")" #955

Open Nayananga opened 3 years ago

Nayananga commented 3 years ago

Wave SDK Version, OS

wave-0.17.0-linux-amd64, Linux

Actual behavior

When Cythonize a project, if it has used @on decorators like this it raises an error,

ValueError(f"@on function '{func_name}' must be async")

Expected behavior

Cythonized project should work as non-cythonized project

Steps To Reproduce

  1. Run Routing example locally
  2. Cythonize the project
  3. Run Cythonized project locally
  4. See error
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [895815] using statreload
Process SpawnProcess-1:
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/usr/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/uvicorn/subprocess.py", line 61, in subprocess_started
    target(sockets=sockets)
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/uvicorn/main.py", line 419, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/uvicorn/main.py", line 426, in serve
    config.load()
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/uvicorn/config.py", line 328, in load
    self.loaded_app = import_from_string(self.app)
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/uvicorn/importer.py", line 20, in import_from_string
    module = importlib.import_module(module_str)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1174, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "routing.py", line 8, in init examples.routing
  File "/home/nayananga/Downloads/Compressed/wave-0.17.0-linux-amd64/examples/venv/lib/python3.8/site-packages/h2o_wave/routing.py", line 82, in wrap
    raise ValueError(f"@on function '{func_name}' must be async")
ValueError: @on function 'clear_cart' must be async
lo5 commented 3 years ago

Thanks for reporting, @Nayananga. If you don't mind, can you please comment out the following two lines in your local install and report back if you run into other issues?

https://github.com/h2oai/wave/blob/master/py/h2o_wave/routing.py#L81-L82

Nayananga commented 3 years ago

@lo5 When I comment those lines and retry, I get this,

(venv) nayananga@nayananga-Aspire-E5-575G:~/PycharmProjects/wave-model-monitoring/build/lib.linux-x86_64-3.8$ wave run src.app
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [1172915] using statreload
INFO:     Started server process [1172918]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:35708 - "POST / HTTP/1.1" 200 OK
Unhandled exception
Traceback (most recent call last):
  File "/home/nayananga/PycharmProjects/wave-model-monitoring/venv/lib/python3.8/site-packages/h2o_wave/server.py", line 305, in _process
    await self._handle(q)
  File "src/app.py", line 27, in serve
  File "src/init.py", line 110, in init_app
  File "src/init.py", line 85, in src.init._create_app_dirs
  File "/usr/lib/python3.8/os.py", line 675, in __getitem__
    raise KeyError(key) from None
KeyError: 'APP_DATA_DIR'
lo5 commented 3 years ago

I'm not sure what that error is. It's originating from src/init.py.

Far0n commented 3 years ago

I have the same issue and after doing https://github.com/h2oai/wave/issues/955#issuecomment-895409563 it runs fine.

Nayananga commented 3 years ago

I'm not sure what that error is. It's originating from src/init.py.

Yes, It was some other issue, commenting those two lines fixed the cythonization issue.

lo5 commented 3 years ago

@Far0n @Nayananga Thanks for confirming.

Related: https://bugs.python.org/issue38225 https://github.com/cython/cython/issues/2273

I'll comment out the checks until the above are resolved.