Prevent lock inversions with GIL in Future (#58391)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/58391
An additional (and hopefully more robust) way of fixing the same problem https://github.com/pytorch/pytorch/pull/58382 fixed.
ghstack-source-id: 129110325
Test Plan: CI
Reviewed By: mrshenli
Differential Revision: D28474154
fbshipit-source-id: 625ebe782e380c60b3ead4c4ed8a51d4bc917153