I tested this on
MacOS 12.3.1 with browsers:
Chrome 109.0.5414.119
Safari 15.4 (17613.1.17.1.13)
I opened 2 tabs and browsed to a simple local server I ran with Python.
The server has 2 workers.
The results are:
Use case 1 - Browse to http://127.0.0.1:5000/
Chrome
2 tabs requesting the same url, e.g. 127.0.0.1:5000/?value=1, are running sequentially. When the 1st tab ends, the 2nd starts.
This means that the 2 tabs both complete after 10 seconds.
It doesn't matter if the tabs are in the same or different windows.
The same port is used by both tabs.
If the tabs are accessing different urls, 127.0.0.1:5000/?value=1 or 127.0.0.1:5000/?value=2, the tabs are running with different ports and in parallel, completing after 5 seconds.
Safari
2 tabs requesting the same url are running in parallel using different ports.
It doesn't matter if the tabs are in the same or different windows.
It doesn't matter if the tabs are accessing the same url.
The tabs are running with different ports and in parallel, completing after 5 seconds.
The FastAPI, Uvicorn server
import asyncio
from fastapi import FastAPI
import uvicorn
from datetime import datetime
app = FastAPI()
class MyClass:
value: str = 'a'
@app.get("/")
async def root(value: int):
MyClass.value = MyClass.value + 'b'
start = datetime.now().strftime("%H:%M:%S")
await asyncio.sleep(5)
end = datetime.now().strftime("%H:%M:%S")
return {
"start": start,
"end": end,
"value": value
}
@app.get("/root2")
async def root2():
MyClass.value = MyClass.value + 'c'
start = datetime.now().strftime("%H:%M:%S")
await asyncio.sleep(5)
end = datetime.now().strftime("%H:%M:%S")
return {
"start": start,
"end": end,
"value": MyClass.value
}
if name == "main":
uvicorn.run("main:app", host="127.0.0.1", port=5000, log_level="info", workers=2)