emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.93k stars 86 forks source link

granian.Granian method is failing #357

Closed sreenivasulureddysura closed 4 months ago

sreenivasulureddysura commented 4 months ago

I can use it in uvicorn below approach

if __name__ == "__main__":
    uvicorn.run("main:app", host='0.0.0.0' port=8080, log_level="info", reload=True)

How to use the granian.Granian with different options?

 import granian
>>> granian.Granian(target='asgi', address='0.0.0.0', port=8000, workers=1).serve()
[INFO] Starting granian (main PID: 20992)
[INFO] Listening at: http://0.0.0.0:8000
[INFO] Spawning worker-1 with pid: 23396
  File "C:\Lib\site-packages\granian\_internal.py", line 40, in load_module
    __import__(module_name)
ModuleNotFoundError: No module named 'asgi'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Python\Python312\Lib\multiprocessing\process.py", line 314, in _bootstrap
  File "C:\Python312\Lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Lib\site-packages\granian\server.py", line 304, in _spawn_rsgi_worker
             ^^^^^^^^^^^^^^^^^
  File "C:\Lib\site-packages\granian\_internal.py", line 58, in load_target
             ^^^^^^^^^^^^^^^^^
    raise RuntimeError(f"Could not import '{module_name}'.")
RuntimeError: Could not import 'asgi'.
[ERROR] Unexpected exit from worker-1
[INFO] Shutting down granian
sreenivasulureddysura commented 4 months ago

@gi0baro Can you help me on this issue?

Found one more issue while running in this format?

if __name__ == "__main__":
    granian.Granian(target='main:app', address='127.0.0.1', port=8000, workers=1).serve()

C:\bot>python app\main.py
[INFO] Starting granian (main PID: 23800)
[INFO] Listening at: http://127.0.0.1:8000
[INFO] Spawning worker-1 with pid: 34268
[INFO] Started worker-1
[INFO] Started worker-1 runtime-1
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "C:\Lib\site-packages\granian\_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "C:\Lib\site-packages\granian\_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "C:\Lib\site-packages\granian\_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
[ERROR] Application callable raised an exception
Traceback (most recent call last):
  File "C:\Lib\site-packages\granian\_futures.py", line 4, in future_watcher
    await inner(watcher.scope, watcher.proto)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FastAPI.__call__() missing 1 required positional argument: 'send'
gi0baro commented 4 months ago

@sreenivasulureddysura target is the application to load, so given your Uvicorn example, this should work:

if __name__ == "__main__":
    granian.Granian("main:app", interface='asgi', address='0.0.0.0' port=8080, log_level="info", reload=True).serve()