-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
Multiprocessing crashes on macOS when a page makes an HTTP request #5780
Comments
I don't think |
Sorry I guess I didn't read your issue in sufficient detail. I suspect there's nothing we can really do about this in Panel, the fix would likely have to be either in Tornado or in Bokeh. |
Does this mean that multiprocessing is not officially supported with For a simple demo app it seemed like the basics work ok (and we stumbled upon this issue, when we tried it in our more realistic app). |
It's a good question, I'd say it's definitely in a gray area. Using import panel as pn
import requests
requests.get("https://panel.holoviz.org")
|
Yes, the issue is still reproducible, as soon as the app gets its first HTTP request (or immediately with |
After some digging it seems that the root cause is in Tornado, which uses os.fork, instead of the I'll try to file an issue with Tornado later this week. |
@philippjfr , I could not reliably reproduce this with a pure Tornado example and I'm out of time, so I'll have to leave following up with Tornado to you, if you would like to have this fixed upstream. The following example, always crashes during the first request, when run from Pycharm and never crashes when run from the Terminal. I could not figure out the difference. I already made sure that import asyncio
import requests
import tornado
from tornado.httpserver import HTTPServer
from tornado.netutil import bind_sockets
from tornado.web import Application
from tornado.web import RequestHandler
class RootHandler(RequestHandler):
def get(self):
html = requests.get("https://www.tornadoweb.org/").content
self.write(html)
app = Application([("/", RootHandler)])
# from here on it's almost a verbatim copy of pattern 2. from https://www.tornadoweb.org/en/stable/httpserver.html
# (except passing the app to HTTPServer and the empty lines)
sockets = bind_sockets(8888)
tornado.process.fork_processes(0)
async def post_fork_main():
server = HTTPServer(app)
server.add_sockets(sockets)
await asyncio.Event().wait()
asyncio.run(post_fork_main()) |
I tried with latest MacOS Sonoma 14.4 (23E214) and latest Python etc pp
None of the examples above crash, not from the MacOS terminal or the VSCode or PyCharm one. @philippjfr - Is there anything that could be improved in Tornado / Bokeh / Panel for multi-processing? Is it still useful to keep this ticket open as reminder? |
ALL software version info
Panel 1.3 or 1.2.3
Python 3.10.12
macOS 14.0
Description of expected behavior and the observed behavior
Panel multiprocessing crashes on macOS when a page makes an HTTP request to a third-party service (e.g. OAuth). This seems to be a known issue with (Python) multiprocessing on macOS and handling it probably requires changes in the multiprocessing code.
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
Workarounds
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
makes the app work, but is not recommended, since it disables an ObjC runtime check which is potentially preventing even nastier bugs (e.g. here).multiprocessing.set_start_method("spawn")
andmultiprocessing.set_start_method("forkserver")
didn't fix the issue.The text was updated successfully, but these errors were encountered: