ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.63k stars 245 forks source link

asyncio + futures support #47

Open socketpair opened 10 years ago

FPurchess commented 10 years ago

+1

klen commented 9 years ago

+2 :)

sdfsdhgjkbmnmxc commented 8 years ago

+1

jie commented 8 years ago

+1

msoedov commented 7 years ago

Bump

stleon commented 7 years ago

+1

pylover commented 7 years ago

+1

pasaranax commented 7 years ago

+1

jammie987 commented 7 years ago

+1

th0mas commented 7 years ago

With new async web frameworks such as Sanic, I would love to be able to use this library with the new async/await syntax.

+1

ziwon commented 7 years ago

+1

cemoody commented 7 years ago

+1

nickmetal commented 6 years ago

Any news?

cypreess commented 6 years ago

+100 ;-)

pingf commented 6 years ago

+1

pawelswiecki commented 6 years ago

+1

anyUesr commented 6 years ago

+1

cyberbudy commented 6 years ago

+1

ulope commented 5 years ago

It would be great to also support trio (an alternative event loop implementation on top of async/await with a much nicer API)

jgirardet commented 5 years ago

https://docs.ponyorm.com/transactions.html#using-db-session-with-generator-functions-or-coroutines is that not enough for now ?

dekoza commented 5 years ago

I'd love to give it a spin using trio.

je111ena commented 5 years ago

Any news regarding this?

sunshineinwater commented 4 years ago

+1 Sanic needs

AstraLuma commented 4 years ago

Ok, so changes that native async needs:

  1. Do not perform blocking IO. That means that you need a new set of database libraries (eg asyncpg).
  2. The asyncness of functions that do IO has to trickle up. So compiling SQL is a CPU-bound task and can still be done the same way. But the functions that send those queries to the database library have to be async, and the functions that glue together the user-facing APIs with the query compiler and the query executors become async, and then the actual public APIs become async.

Honestly, the simpler way is to use the integration of asyncio and concurrent.futures to make async proxies that send the work to a background thread, rather than trying to retool an entire library to be async. Preferably with a heavy dose of metaprogramming.

And no, I don't know of any tools that will allow a single source to act as both sync and async. In theory, you could strip all the async-related keywords, but you still need a way to interact with the libraries you talk to (either by switching libraries or wrapping in a sync-async bridge).

Trust me, I've been down this road, I have my own library that attempts to live in both worlds. It's not great.

JuniorJPDJ commented 4 years ago

@astronouth7303 telethon is using own synchronizer for async API to be able to be used as sync lib You should take a look ;)

phacic commented 4 years ago

+2

MioYvo commented 3 years ago

+1

jinCN commented 3 years ago

When Pony does not perform blocking IO and start use async/await, will lazy fetch still be usable?

I mean, before thinking modifying Pony. Lazy fetch does conflict with async/await. How can this problem be solved?

Ok, so changes that native async needs:

  1. Do not perform blocking IO. That means that you need a new set of database libraries (eg asyncpg).
  2. The asyncness of functions that do IO has to trickle up. So compiling SQL is a CPU-bound task and can still be done the same way. But the functions that send those queries to the database library have to be async, and the functions that glue together the user-facing APIs with the query compiler and the query executors become async, and then the actual public APIs become async.

Honestly, the simpler way is to use the integration of asyncio and concurrent.futures to make async proxies that send the work to a background thread, rather than trying to retool an entire library to be async. Preferably with a heavy dose of metaprogramming.

And no, I don't know of any tools that will allow a single source to act as both sync and async. In theory, you could strip all the async-related keywords, but you still need a way to interact with the libraries you talk to (either by switching libraries or wrapping in a sync-async bridge).

Trust me, I've been down this road, I have my own library that attempts to live in both worlds. It's not great.

levrik commented 3 years ago

I'm wondering since the most awesome part of Pony is the SQL query builder if this could be used standalone, so it the resulting queries could be used with an async client? Or someone could build an async Pony by importing the query builder but rebuilding with async in mind?

Ed-XCF commented 3 years ago

I'm wondering since the most awesome part of Pony is the SQL query builder if this could be used standalone, so it the resulting queries could be used with an async client? Or someone could build an async Pony by importing the query builder but rebuilding with async in mind?

maybe a pure Pony SQL query builder is a key for aio pony

wozniakty commented 3 years ago

👀 I want so badly to use Pony, but async is the future. Plz <3

homus32 commented 3 years ago

+999999999

JuniorJPDJ commented 3 years ago

Guys, instead of writing +1 and obfuscating discussion, please just add your finger up on issue.

KochankovID commented 3 years ago

+

taylor-shift commented 2 years ago

bump

nightstream commented 2 years ago

Ah, this is an issue opened since 2014........

j4hangir commented 2 years ago

Is there any plan for this? I saw some benchmarks for pony and it already performs surprisingly well, I'd venture using asyncio it'd get even faster making it suitable for heavy-duty projects.

KhanhhNe commented 2 years ago

Async would be great, but actually, if you want to use the library with Trio, you can use trio.to_thread.run_sync() (docs) to run a sync function containing the database communication. In that case, it won't block the event loop, and won't need PonyORM to be rewritten also.

v3ss0n commented 1 year ago

But it would nullify the advantage of asyncio frameworks by spawning threads which are memory intensive and not optimal in python , compare to async which is designed for IOs.

ShadowJonathan commented 1 year ago

It would also not be a convenient or nice wrapper, as Pony's ORM is supposed to take advantage of a descriptive object-method model, which you can't stuff in a single wrapper.

Unless you'd wrap every single Pony interaction into a lambda/local function to spawn on a synchronous thread (and flip-flopping between sync and async on code blocks), it's just not easily possible, that's why this issue exists; to encourage pony devs to give us a high-level API for this, even if it'll spawn those same underlying operations synchronously on a thread pool.

KhanhhNe commented 1 year ago

But it would nullify the advantage of asyncio frameworks by spawning threads which are memory intensive and not optimal in python , compare to async which is designed for IOs.

Actually I think it wont be too bad, considering currently I have to use threads to do work & do Pony queries anyway. An asyncio interface would help integrate better & easier with asyncio based systems, and I think minor performance tradeoff is reasonable.