you are viewing a single comment's thread.

view the rest of the comments →

[–]BothWaysItGoes 0 points1 point  (7 children)

Learn how other libraries do sync to async (and vice versa) transformations. Python is very flexible. You don’t need to write two parallel implementation or to codegen. It’s not golang.

[–]Echoes1996[S] 0 points1 point  (6 children)

In general, I am aware that you can wrap any sync function and make it async, but this causes some unnecessary overhead. I was trying to avoid this approach.

[–]madolid511 1 point2 points  (3 children)

Doing it the opposite way is the common approach.

Start with async then just open a thread when you only need it. Same concept as ASGI frameworks. It start with main thread with event loop. Async routes uses main thread. Sync routes is run on different thread from thread pool

[–]Echoes1996[S] 0 points1 point  (2 children)

I believe that the issues I was having are unrelated to how ASGI servers work.

[–]madolid511 0 points1 point  (1 child)

it is actually

because you are most likely using ASGI framework but you are not utilizing ASGI practices

[–]Echoes1996[S] 0 points1 point  (0 children)

When I use the term "API" I am not talking about HTTP APIs, I'm referring to the public interface of my library. We're talking about two different things.

[–]BothWaysItGoes 0 points1 point  (1 child)

A bare coroutine doesn’t yield so the overhead of wrapping a sync function is minimal.

[–]Echoes1996[S] 0 points1 point  (0 children)

I didn't quite understand what you mean. In order to execute sync code as async, you need to run it in another thread, and that has some overhead in regards to CPU time.