numbas / numbas-lti-provider

An LTI tool provider to run Numbas exams
https://docs.numbas.org.uk/lti/en/latest/
Other
11 stars 12 forks source link

Error: You cannot span multiple processes with the in-memory layer... #48

Closed wade-tattersall closed 6 years ago

wade-tattersall commented 6 years ago

I'm trying to set-up a numbas-lti server at my institution. I've followed the instructions as per the documentation, as near as I can tell, although I've had to make minor tweaks because I'm running on RHEL 6 instead of Ubuntu. I'm using nginx as recommended. I have some Django experience and a lot of general python experience, but I'm new to Channels.

I think I had to copy the settings.py.dist file to settings.py, and then first_setup.py was able to complete the templating.

However, the settings for the channels is

CHANNEL_LAYERS = {                                                                                                                                            
    "default": {                                                                                                                                              
        "BACKEND": "asgiref.inmemory.ChannelLayer",                                                                                                          
        "ROUTING": "numbasltiprovider.routing.channel_routing",                                                                                               
    },                                                                                                                                                        
}

When I try to run the worker processes with /srv/numbas-lti-provider/manage.py runworker, either manually or through the supervisor task, it crashes with

CommandError: "You cannot span multiple processes with the in-memory layer. Change your settings to use a cross-process channel layer."

This is unsurprising, since the daphne server is a separate process to the workers, so of course an in-memory layer won't work, so I don't understand why numbas-lti's settings are set to use that backend.

From stepping through the code I can't see any way 'runworker' can be used with an inmemory backend at all.

Notably, the daphne process takes a numbasltiprovider.asgi:channel_layer parameter in the supervisor config. Should there be some equivalent for the worker processes?

What have I done wrong?

christianp commented 6 years ago

Hi Wade, You've done nothing wrong, I have! We don't use that configuration in production, and I shouldn't have put it in the example settings. We use this:

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_redis.RedisChannelLayer",
        "CONFIG": {
            "hosts": [os.environ.get('REDIS_URL','redis://localhost:6379')],
        },
        "ROUTING": "numbasltiprovider.routing.channel_routing",
    },
}
christianp commented 6 years ago

I've updated first_setup.py so it sets CHANNEL_LAYERS correctly. You can either run that again, or copy the code I put above, to get the right channel layer. Please let me know how you get on, and close this issue if you get it working.

wade-tattersall commented 6 years ago

Thank you, it works perfectly.