forked from buguroo/pyknow
-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
bugSomething isn't workingSomething isn't working
Description
I use the KnowledgeEngine as my Rule Engine. but the instance Of Light() ect would not actually release in memory.
I use it with a loop and at least 10000 user which has a large number Fact. The amount of memory will raise very quickly and be killed because of the memory is not enough.
Try to use gc.collect(). But it has the same result. And I need some help about that. Thanks.
This is my test sample of Light() has not be release in memory after the loop. And I use objgraph package for checking it .
# here's the demo code use by a loop
from random import choice
from experta import *
class Light(Fact):
"""Info about the traffic light."""
pass
class RobotCrossStreet(KnowledgeEngine):
@Rule(Light(color='green'))
def green_light(self):
print("Walk")
@Rule(Light(color='red'))
def red_light(self):
print("Don't walk")
@Rule(AS.light << Light(color=L('yellow') | L('blinking-yellow')))
def cautious(self, light):
print("Be cautious because light is", light["color"])
def test_func():
engine = RobotCrossStreet()
engine.reset()
engine.declare(Light(color=choice(['green', 'yellow', 'blinking-yellow', 'red'])))
engine.run()
# will do some record..
if __name__ == '__main__':
import objgraph
objgraph.show_growth()
for i in range(10):
test_func()
print('======after======')
objgraph.show_growth()
# the first print of show_growth()
'''
function 2389 +2389
dict 1211 +1211
wrapper_descriptor 1043 +1043
tuple 831 +831
builtin_function_or_method 789 +789
method_descriptor 743 +743
weakref 731 +731
getset_descriptor 455 +455
member_descriptor 299 +299
type 231 +231
'''
# the second print of show_growth
'''
dict 1311 +100
weakref 786 +55
set 155 +46
builtin_function_or_method 821 +32
FactCapture 30 +30
list 209 +29
Light 32 +29 <---- here
tuple 858 +27
method 43 +15
ChildNode 15 +15
'''Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working