Multiple workers with vue.js as frontend

We build a project with Sanic and vue.js on Windows. When we try to run the app with more than 1 worker we have the following error:

AttributeError: Can’t pickle local object ‘register.._handler’

However, when we comment the following line out, sanic starts with multiple workers but of course doesn’t serve the static files:

app.static(‘static’, ‘…/…/dist/static’)

Isn’t sanic able to run with multiple workers and serve static files at all?

main.py:

app = Sanic()
app.static('/static', './dist/static')
@app.route('/')
async def index(request):
    template = open(os.getcwd() + '/dist/index.html')
    return html(template.read())

run.py

if __name__ ==  "__main__":
    app.run(host='0.0.0.0', port=5000, workers=2)

Hello, @Toby! This is indeed a good question. I’m not all that familiar with Sanic running on Windows (even though I created a dev environment some time ago), so I’m very skeptical regarding multiple workers on Windows (yet).

Can you run this code on Linux to see if it works as expected?

Cheers,
Richard.

Hi Richard

We tried it on mac and it worked with multiple workers. So it looks like a windows issue. Unfortunately it has to run on windows. By the way we use python 3.6.6. Thank you for your answer.

Toby

@Toby that’s an interest issue, I think you should open one on Github regarding this - I don’t know how far Windows can handle multiprocessing and the limits imposed (perhaps a file handler descriptor may be one of them …)