Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Uvicorn Detect --reload Main Thread

I have a simple Uvicorn application (built with FastAPI). In development, uvicorn server:app --reload. The --reload paramter means two threads will be started, one with the server, one to monitor file changes—when a file change is detected, the thread with the server is restarted.

Nothing special thus far. This is common in Flask, Django, and other dev servers as well. The catch is, I want to open a tunnel using pyngrok when I start the dev server, and I want that tunnel to be as long lived as the parent of these two threads. That is to say, when a file change is detected and the dev server is restarted, I do not want the tunnel to be restarted (since with ngrok this would cause a new public URL to be generated and break existing connections).

With Flask and Django this is relatively easy to accomplish. For example, with Flask I simply do os.environ.get("WERKZEUG_RUN_MAIN") != "true", with Django I similarly evaluate the RUN_MAIN environment variable, and in either case I only instantiate the tunnel when this these are set to true. I can't find a similar variable to use with Uvicorn. Can anyone help out here?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!