This is a very exciting project - thanks for releasing this!
I tried to get it working with my https://datasette.io/ ASGI app and ran into this error:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/context.py", line 288, in _Popen
return Popen(process_obj)
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 47, in _launch
reduction.dump(process_obj, fp)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'asgi_csrf_decorator.<locals>._asgi_csrf_decorator.<locals>.app_wrapped_with_csrf'
Here's the script I wrote to replicate the problem, saved as serve_datasette_with_granian.py
:
from granian.server import Granian
from granian.constants import HTTPModes, Interfaces, Loops, ThreadModes
from granian.log import LogLevels
from datasette.app import Datasette
def serve_with_granian():
ds = Datasette(memory=True)
app = ds.app()
Granian(
app,
address="127.0.0.1",
port=8002,
interface=Interfaces.ASGI,
workers=1,
threads=1,
pthreads=1,
threading_mode=ThreadModes.workers.value,
loop=Loops.auto.value,
http=HTTPModes.auto.value,
websockets=True,
backlog=1024,
log_level=LogLevels.info.value,
ssl_cert=None,
ssl_key=None,
).serve()
if __name__ == "__main__":
serve_with_granian()
Run it like this to see the error (run pip install datasette
first):
python serve_datasette_with_granian.py
Are there changes I can make to Datasette to get this to work, or is this something that illustrates a bug in Granian?
Relevant Datasette code is here: https://github.com/simonw/datasette/blob/6a352e99ab988dbf8fd22a100049caa6ad33f1ec/datasette/app.py#L1429-L1454
It's applying my asgi-csrf
ASGI middleware from https://github.com/simonw/asgi-csrf
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too