-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: Can't pickle local object 'register.<locals>._handler'
sanic 19.12.2; python3.8.2; sanic-cors==0.10.0.b1
#1774
Comments
For triaging: this is now a problem because Python 3.8 changes the default mode of This could be worked around by forcing |
Hi @Tronic - many thanks for this. We write code on a mixture of OSX and Linux, and deploy to Linux, so in our particular instance, not being able to fork on Windows is not going to cause a problem. We do have complex objects being passed to the workers, but I had though that those with connections to databases (which we know cannot be pickled) were created only in |
@Tronic a comment related to this: I thought I added tests to ensure a sanic app could be fully pickled and unpickled without error. Looks like now some code has been introduced at some point that has a local sub_function, which isn't pickleable, or perhaps its only a problem on Python 3.8, which I think our test suite isn't running properly yet. |
@ashleysommer Would it be viable to move most app initialisation to within workers, instead of pickling it from the main process? Only server socket opening really needs to be in the master process, while app definition and other user code could be run in workers. Getting this done would need quite a bit of refactoring, but barring that, it could be the clean solution to this. Doing so would avoid troublesome pickling and the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions. |
This still needs to be fixed. |
@Tronic I have some (hopefully good) news. Our project was busy for a few months but last week we got around to putting effort back into our py38 upgrade. Somewhere along the lines we had also re-checked all code to ensure that calls to set up connections to external databases (we have three external connection pools to three different kinds of database) were made in We were happily surprised to find that due to ensuring we created our connections "after_server_start" we can start the sanic At this stage I can think of two possible next steps: 1: a note in the docs (and a review of existing examples) to state that connections to databases should be created "after_server_start" @Tronic - what's the best way to proceed? |
I don't think that before vs. after server start should make a difference for pickling. Both are done in worker processes, and only According to your traceback, the |
Ah - I clearly still don't understand the inner working yet then. I can't relate the string |
Are you no longer using |
I believe this could be fixed quite easily by rewriting Pinging anyone who cares: pull requests are welcome! |
Moves the subfunction _handler out to a module-level function, and parameterizes it with functools.partial(). Fixes the case when picking a sanic app which has a registered static route handler. This is usually encountered when attempting to use multiprocessing or auto_reload on OSX or Windows. Fixes sanic-org#1774
Moves the subfunction _handler out to a module-level function, and parameterizes it with functools.partial(). Fixes the case when picking a sanic app which has a registered static route handler. This is usually encountered when attempting to use multiprocessing or auto_reload on OSX or Windows. Fixes sanic-org#1774
Moves the subfunction _handler out to a module-level function, and parameterizes it with functools.partial(). Fixes the case when picking a sanic app which has a registered static route handler. This is usually encountered when attempting to use multiprocessing or auto_reload on OSX or Windows. Fixes sanic-org#1774
@Tronic Sorry for the delay in getting back to you. Our code doesn't use app.static directly, but has been (for over a year) and still does, use blueprint.static - that part of the code has not changed. |
Hi.
On OSX 10.14.6, python 3.8.1
I cannot start an API due to
The text was updated successfully, but these errors were encountered: