Fix #896: use asyncio.run() so idb launches on Python 3.10+#924
Fix #896: use asyncio.run() so idb launches on Python 3.10+#924DrunkOnJava wants to merge 1 commit into
Conversation
Python 3.10 deprecated implicit-loop creation in asyncio.get_event_loop();
3.12+ raises RuntimeError("There is no current event loop in thread")
unless an event loop is explicitly set on the current thread. By
Python 3.14 (the default brew formula now) calling 'idb' or 'idb
udid' immediately crashes:
RuntimeError: There is no current event loop in thread 'MainThread'
asyncio.run() is the canonical CLI entrypoint introduced in Python 3.7.
It creates a fresh event loop, runs the coroutine, and closes the loop
(including cancelling pending tasks) in one call — exactly what the
existing get_event_loop()+close() block was doing manually, but without
the deprecated implicit-loop creation.
Closes facebook#896 (reported 2025-11-26, marked completed in 2026-02 with a
user workaround comment but never patched upstream; still reproducing
on fb-idb 1.1.7 / Python 3.14.2 as of 2026-04-10).
|
Hi @DrunkOnJava! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
Pull request overview
Replaces the deprecated asyncio.get_event_loop() + run_until_complete() pattern in the CLI entrypoint with asyncio.run(), fixing a startup RuntimeError on Python 3.10+ (issue #896).
Changes:
- Swap manual loop management for
asyncio.run(gen_main(cmd_input))inidb/cli/main.py::main(). - Add an explanatory comment block documenting the rationale and Python version context.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
idb/cli/main.py::main()callsasyncio.get_event_loop()at top-level, which on Python ≥ 3.10 raises:…when no event loop has been explicitly set on the main thread. Python 3.10 deprecated implicit-loop creation; 3.12+ enforces it as a hard error. By 3.14 (now the default for
brew install pythonon macOS)idbwill not launch at all — every invocation crashes during startup. This blocksidb,idb udid,idb list-targets, etc. for any user on a modern Python.The fix
Replace the manual
asyncio.get_event_loop()+loop.run_until_complete()+loop.close()pattern withasyncio.run(...). This is the canonical CLI entrypoint introduced in Python 3.7. It:Behaviour is identical to the previous pattern on Python 3.7-3.9 (where
get_event_loop()auto-created a loop when none existed), and now also works on 3.10-3.14+.Context
fb-idb 1.1.7/ Python3.14.2(currentbrewdefaults) today.patch-idb.shscript that rewrites the function in-place after everybrew upgrade. This PR upstreams the fix so that's no longer necessary for anyone.Test plan
pipx install --python python3.14 fb-idbfrom this branch's wheel)idb list-targets— should print target list (not RuntimeError)idb udid— should print UDID (not RuntimeError)sys.exit(main())inmain_2())Notes
This is a one-line semantic change wrapped in a comment block explaining the why. The previous form's
try/finallywas redundant given thatasyncio.run()already handles loop cleanup; removing it is intentional, not a bug.