Bound thread length when doing custom threading.

Summary:
This should fix the recursion depth exceeded error we keep seeing. It's also
probably not a good idea to let threads get super long anyways.

Fixes T434.

Test Plan: Unit test added.

Reviewers: khamidou

Reviewed By: khamidou

Maniphest Tasks: T434

Differential Revision: https://review.inboxapp.com/D508