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.

RFC: Multi-application serve

See original GitHub issue

Background

Running multiple applications has been possible in Sanic for a long time. It does, however, take a pretty decent understanding of the operation of the Sanic server to do it properly. Things to consider include:

  • loop management
  • listener execution
  • startup time optimizations
  • multi-worker and auto-reload multiprocessing
  • cross-platform support issues (looking at you Windows)

Over the course of the last six months in particular, I have seen a noticeable rise in the number of support queries where people are trying to do this. Whether it is to have a HTTP >> HTTPS proxy, web server plus chatbot, or serve multiple routes on different host/port configurations, the point is that there is a definite rise in the number of people looking to run multiple Sanic applications side-by-side.

With the efforts we have taken to make sure that multiple applications can co-exist, it seems only natural that we provide a first-class API for running them.

Proposed solution

We create a new high-level API that can easily handle this.

First, we create a method with an identical signature to app.run. Its job is to do everything that app.run would do, cache the server_settings for later usage, and stop at the point where it starts the loop.

app1 = Sanic("ApplicationOne")
app2 = Sanic("ApplicationTwo")

app1.prepare(port=7777)
app2.prepare(unix="/path/to/sock")

Second, there is a single class method that runs the loop and executes the server(s).

Sanic.serve()

The first application defined in the application registry becomes the “primary.” That application is run normally as would otherwise happen with app.run. Any other applications in the registry that have been “prepared” will be setup using create_server such that all of their lifecycle events are properly run.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ahopkinscommented, Jan 5, 2022

@Tronic

from sanic import Request, Sanic, json

app = Sanic("one")


@app.get("/")
async def handler(request: Request):
    return json({"foo": 1})


app.prepare(host="127.0.0.1", debug=True)
app.prepare(host="::1")
Sanic.serve()

image

0reactions
ahopkinscommented, Jan 5, 2022

I am hoping to get #2347 finalized and merged in the next week or so. There are enough structural changes to how applications are started that it would be worth it to get this in before progressing too much further with HTTP/3. It would be great if we could get the initial HTTP/3 support out in March.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RFC 3958 - Domain-Based Application Service Location ...
Domain-Based Application Service Location Using SRV RRs and the Dynamic Delegation Discovery Service (DDDS) (RFC 3958, January 2005)
Read more >
how to configuration PO RFC sender | SAP Community
hello all i meet a question ,when we have a RFC SENDER interface transfer to P ... multi-Application server in sap P environment,...
Read more >
RFC 1193: Client requirements for real-time communication ...
1. Introduction We call real-time a computer communication service whose clients are allowed to specify their performance requirements and to obtain guarantees ...
Read more >
Load balancing settings - Saptechnicalguru.com
Larger productive systems have multiple application servers to ... With transaction RZ12 you can setup RFC server groups that also can be ...
Read more >
Configuring the Inbound Adapter Configuration for Multiple ...
Configuring the Inbound Adapter Configuration for Multiple Application Servers ... During configuration, ensure that each BAPI/RFC/IDoc service ...
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