<p dir="auto">Hello,</p>
<p dir="auto"><em>Note: I posted this question in "discussions" but not sure it was the right place I apologize for the duplicate</em></p>
<p dir="auto">Coming from Scala where the management of asynchronous/synchronous operations is quite explicit, I am struggling to understand what's the impact of using def instead of async def for path operation functions.</p>
<p dir="auto">My main motivation by using an async framework is to be able to scale a lot on a single machine, being able to support a high number of concurrent http requests with a limited number of system threads.</p>
<p dir="auto">Using a mature database access library like SQL Alchemy will require to use non async functions a lot, as it does not support async yet (I know there are options but I am not sure I want to use it). The doc claims that then the function runs on a separate thread pool.</p>
<p dir="auto">Does that mean:<br>
1/ a new thread will be created for each new http client request: in that case I guess the async nature of fastapi just disappear...</p>
<p dir="auto">2/ a new thread will be created just for a new sql connection/session while keeping the requests handlers async on the main pool ? In that case what kind of thread is it ? is it a fixed thread pool ? is the number of threads configurable ? How will it be managed regarding the number of connections in the connection pool (dead locks ...) ?</p>
<p dir="auto">Thanks for your help !<br>
--pascal</p>
<h3 dir="auto">First check</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I added a very descriptive title to this issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I used the GitHub search to find a similar issue and didn't find it.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I searched the FastAPI documentation, with the integrated search.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already searched in Google "How to X in FastAPI" and didn't find any information.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already read and followed all the tutorial in the docs and didn't find an answer.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/samuelcolvin/pydantic">Pydantic</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/swagger-api/swagger-ui">Swagger UI</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I already checked if it is not related to FastAPI but to <a href="https://github.com/Redocly/redoc">ReDoc</a>.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> After submitting this, I commit to one of:
<ul dir="auto">
<li>Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.</li>
<li>I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.</li>
<li>Implement a Pull Request for a confirmed bug.</li>
</ul>
</li>
</ul>

<h3 dir="auto">Example</h3>
<p dir="auto">Here's a self-contained, <a href="https://stackoverflow.com/help/minimal-reproducible-example" rel="nofollow">minimal, reproducible, example</a> with my use case:</p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from fastapi import FastAPI

app = FastAPI()


@app.get('/cookies')
def cookie(name=Cookie(None)):
    return {'name': name}"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">fastapi</span> <span class="pl-k">import</span> <span class="pl-v">FastAPI</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">FastAPI</span>()


<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">get</span>(<span class="pl-s">'/cookies'</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">cookie</span>(<span class="pl-s1">name</span><span class="pl-c1">=</span><span class="pl-v">Cookie</span>(<span class="pl-c1">None</span>)):
    <span class="pl-k">return</span> {<span class="pl-s">'name'</span>: <span class="pl-s1">name</span>}</pre></div>
<h3 dir="auto">Description</h3>

<ul dir="auto">
<li>Run the above code</li>
<li>Goto swagger to test the cookies.</li>
<li>The name is returned as null instead of what was input.</li>
</ul>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/8587189/90330110-15c76b80-dfca-11ea-9c87-323adb042b85.png"><img src="https://user-images.githubusercontent.com/8587189/90330110-15c76b80-dfca-11ea-9c87-323adb042b85.png" alt="Screenshot from 2020-08-16 14-06-41" style="max-width: 100%;"></a></p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: [e.g. Linux / Windows / macOS]: Linux</li>
<li>FastAPI Version [e.g. 0.3.0]: 0.60.1</li>
</ul>
<p dir="auto">To know the FastAPI version use:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="python -c &quot;import fastapi; print(fastapi.__version__)&quot;"><pre class="notranslate">python -c <span class="pl-s"><span class="pl-pds">"</span>import fastapi; print(fastapi.__version__)<span class="pl-pds">"</span></span></pre></div>
<ul dir="auto">
<li>Python version:</li>
</ul>
<p dir="auto">To know the Python version use:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="python --version"><pre class="notranslate">python --version</pre></div>
<h3 dir="auto">Additional context</h3>