Alexander
You can use lambdas too, for more complex queries: Activite.get(lambda p: p.matiere == x and p.famille == y and p.something > z)
Alexey
Jim I actually like lambdas better. How about you guys?
stsouko
Sometimes classic kwargs is useful
Jim
Since I use pony I progressively stooped to use lambdas. At the beginning I was using lambdas and generator expressions. I was always mixing everything and writing bad syntax.. So I now use select for almost everything (more "pythonic", gen exp/comprehesion is a well known syntax, more granularity to select only some fields). About the get,as can see I was a bit lost since I was using it only for for primarykeys before. Looking at it now, If possible I will use kwargs I think : shorter, dict unpacking. Thank you everyone for this short reminder
Xavier
Hi, I have a quesetion related with memory usage. The select() returns an iterator ? If I do list(select()) I use more memory?
Alexander
select() returns query object. Once query is executed it has all objects in memory.
Xavier
so there is no diference?
Alexander
Yes. How would you save the memory?
Xavier
yes
Xavier
because it's a big query
Alexander
Fetching objects one by one will take huge amount of time
Jim
maybe fetching on a batch mode ?
Jim
there is page() function in pony may it could be usefull for it (i never used it)
Alexander
As I remember page is a combination of limit and offset
Matthew
Even if you use pagination the pony cache will expand as you load more objects. You would need to empty the cache.
Alexander
At this moment Pony does not have a batch mode, because all loaded objects stays in memory until the end of db_session It is hard to say which objects can be garbage collected PonyORM uses IdentityMap pattern where object loaded during db_session are stored inside identity map and interconnected via relationships. In other ORMs which implement Active Record pattern it is easier to garbage collect objects, because ORM itself does not hold any references to previously loaded objects. But on the other hand you will have multiple copies of the same object, it it was loaded several times. Maybe in the future we can invent some way to determine which objects can be garbage collected
Alexander
It would be equivalent to commit() rollback() Note that you can’t use previously loaded objects after this
Abuelazo
hola, alguien asignar el atributo time ejemplo hrs = Required(Time)
Jim
hrs = Required(datetime.datetime)
Abuelazo
hrs = Required(datetime.datetime)
hrs_trab = Required(datetime.datetime) AttributeError: type object 'datetime.datetime' has no attribute 'datetime
Jim
thre is from datetime import datetime before ? only Required(datetime) then
Luis
Or import datetime and use datetime.datetime
Abuelazo
sigue dando el mismo resultado
Jim
show us your code
Abuelazo
https://pastebin.com/rip6Nbrx
Abuelazo
class Registro_actividades
Jim
You import datetime beforr line 6
Abuelazo
hrs_trab = Required(datetime.datetime) AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
Alexander
As you import looks like from datetime import datetime you need to write hrs_trab = Required(datetime)
Abuelazo
solucionado muchas gracias 👍🏼
csa3d
Is it possible to store uint64 data without conversion
Alexander
attr = Required(int, size=64)
Alexander
should work
csa3d
Awesome sauce
csa3d
Ty
Matthew
with db_session: x = X.select().first() x.y += 1 commit() rollback() Will this get the object, increment its field, commit the transaction, then remove the object from the in-memory cache?
Alexander
Yes, and you can also add strict=True option to db_session to be sure objects which are interlinked by relationships are disconnected from each other, it should make garbage collector work easier
Matthew
Great! thank you. Hopefully this will reduce the memory usage of some background workers which load a lot of pony objects
Matthew
Is there any way to tell python to free memory from the heap back to the system after dropping a bunch of objects?
Matthew
Google didn’t show anything
Alexander
you can do import gc; gc.collect() but with db_session(strict=True) it is probably not necessary
Matthew
Is it a problem if I have two nested strict db_sessions?
Alexander
I think no, inner will be ignored
Matthew
thank you 🙂
Rick
hi! how can I get n random elements from a table?
Alexander
What is the primary key of the table, is it just id?
Alexander
MyEntity.select_random(n)
Rick
but I have another column (category) and I want to filter out some of these
Alexander
hmm, then:
Alexander
MyEntity.select(lambda obj: obj.category == x).random(n)
Rick
thank you very much! you're the best
Rick
MyEntity.select(lambda obj: obj.category == x).random(n)
I have this error: AttributeError: module 'parser' has no attribute 'suite'
Alexander
Can you show full traceback?
Rick
Alexander
Ok, give me a few minutes...
Rick
Sure, don't worry :P
Alexander
Do you use Python 3.8?
Rick
yeah
Alexander
It looks strange, because function parser.suite presents in Python 3.8 documentation https://docs.python.org/3/library/parser.html#parser.suite Python 3.8.0 (default, Nov 6 2019, 16:00:02) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import parser >>> parser.suite <built-in function suite> >>>
Alexander
Everything works good on my machine. Can you do some minimal script which reproduces the problem?
Rick
Everything works good on my machine. Can you do some minimal script which reproduces the problem?
https://privatebin.net/?08f0a4d3310e05fc#ETN1nq9X6TtwsecgKJj5H2ZRvK178RNQM6iRwCNNyX39 edit: traceback: https://privatebin.net/?8ce2687d50654b3c#7axg1GvWGyAL7iH2kvFqU8WCMa5tLo1Fzv8jgBbaktrn
Rick
@metaprogrammer my bad!! I had a file in the root folder named parser.py
Rick
I renamed it and now it works
Alexander
Cool
Rick
I'm very sorry!
Alexander
No problem :)
Anna
thank you very much! you're the best
I must say -- much respect for the Rick&Morty avatar!! 🔥🔥🔥
Jorge
Good morning! i have an issue with a little API using aiohttp + ponyorm
Jorge
I don't know if is a memory leak or cache
Jorge
The API is a POST operation inserting 2 entities and returing a property
Jorge
every time the api gets a request the python process up 0.1 MB
Jorge
On startup, I instantiate the database object, then, per request aiohttp call an async custom function handler and this handler call a function with the db_session decorator
Jorge
Jorge
the async function handler