question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

launch server as task?

See original GitHub issue

Currently uvicorn.run() calls Server.run(...) which calls loop.run_until_complete(...). Additionally uvicorn insists on starting the loop itself too (in setup_loop)

As such, it is made very difficult to launch other tasks in the same process.

Is there a way to launch the server as just a task on the loop and have the ability to schedule additional tasks on the loop?

IIUC there were some related issues in the past but not clear to me what is going to happen with these.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
rob-blackbourncommented, Aug 9, 2019

Hi @toonknapen ,

This is a problem that I’ve had to solve, so I wrote a blog entry on it here. I think the bit right at the end might be what you’re looking for.

0reactions
tomchristiecommented, Oct 24, 2019

We’ve added a Config(loop="none") option now, if you really need it. Also see server.serve(...) if you want to run the uvicorn server from within an existing async context.

On the whole the ASGI lifespan messaging is the right way to include application startup or scheduled background tasks.

I’m wondering if we ought to include a startup=<some_func> and shutdown=<some_func> options, that hook in startup and shutdown tasks easily? That might be easier for folks in cases where they’re not using an application framework that provides those hooks itself?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schedule a server process in - Windows - Microsoft Learn
Schedule the Task. Click Start, point to Control Panel, then point to Scheduled Tasks, and then click Add Scheduled Task.
Read more >
How can I run a scheduled task as SYSTEM - Super User
Go to Start > Administrative Tools > Task Scheduler; In the Task Scheduler window click "Create Task" on the right hand bar under...
Read more >
Automatically starting a server when starting a debug session ...
The `start server` task is a `shell` task, should run in the background and the command it executes is `http-server`, which is the...
Read more >
How to configure your server to run Scheduled Tasks
1) Go to Start → Control Panel → Administrative Tools → Task Scheduler (or Scheduled Tasks on earlier versions of Windows) · 2)...
Read more >
9 ways to start the Task Scheduler in Windows (all versions)
You can open the Task Scheduler using the Task Manager too. Press the Ctrl + Shift + Esc keys on your keyboard to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found