(I tried to reproduce this for few months and today I did it >_<)
import gc
from datetime import datetime
from pony.orm import *
db = Database()
class Author(db.Entity):
comments = Set('Comment')
class Post(db.Entity):
pass
class Comment(db.Entity):
author = Required(Author)
db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)
# prepare data
print('fill database...')
with db_session:
a = Author(id=1)
for i in range(2, 5000):
Author(id=i)
Post(id=i)
Comment(author=a)
del a
# test it!
@db_session
def testme():
author = Author.get(id=15)
comments_list = Comment.select(lambda x: x.author.id == author.id)
ids = list(select(x.id for x in Post))
print('started')
while True:
testme()
gc.collect()
If you run it, then memory of python process will leak (+8MB per second on my machine).
Very strange things that prevented me from reproducing it:
- If you append
author_id = author.id and replace == author.id with == author_id, then everything is fine.
- OR if you just comment/delete line
ids = ..., then everything is fine too!
WTF?
(I tried to reproduce this for few months and today I did it >_<)
If you run it, then memory of python process will leak (+8MB per second on my machine).
Very strange things that prevented me from reproducing it:
author_id = author.idand replace== author.idwith== author_id, then everything is fine.ids = ..., then everything is fine too!WTF?