Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/brain.py
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-12-18 22:40:41 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-12-18 22:40:41 (GMT)
commitfcbf9cf59b4108e3bb4218f5d8e642eed850ae0a (patch)
tree9f183001fb47d9076c408410cd1e357c5efc9457 /brain.py
parent683877910d9194253dc6f46fe0021f038e92578b (diff)
talk to computer crashes #2533
Reduce alisochka.brn by one third; check for free momory before loading brains.
Diffstat (limited to 'brain.py')
-rw-r--r--brain.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/brain.py b/brain.py
index 2cbaa34..4ceb47e 100644
--- a/brain.py
+++ b/brain.py
@@ -39,10 +39,20 @@ BOTS = {
'predicates': { 'name': 'Alice',
'master': 'the Sugar Community' } } }
+
+def get_mem_info(tag):
+ meminfo = file('/proc/meminfo').readlines()
+ return int([i for i in meminfo if i.startswith(tag)][0].split()[1])
+
+
# load Standard AIML set for restricted systems
-if int([i for i in file('/proc/meminfo').readlines()
- if i.startswith('MemTotal:')][0].split()[1]) < 524288:
- BOTS[_('English')]['brain'] = 'bot/alisochka.brn'
+if get_mem_info('MemTotal:') < 524288:
+ mem_free = get_mem_info('MemFree:') + get_mem_info('Cached:')
+ if mem_free < 102400:
+ BOTS[_('English')]['brain'] = None
+ else:
+ BOTS[_('English')]['brain'] = 'bot/alisochka.brn'
+
_kernel = None
_kernel_voice = None
@@ -64,10 +74,11 @@ def get_voices():
def respond(voice, text):
- if _kernel is None:
- return text
- else:
- return _kernel.respond(text)
+ if _kernel is not None:
+ text = _kernel.respond(text)
+ if _kernel is None or not text:
+ text = _("Sorry, I can't understand what you are asking about.")
+ return text
def load(activity, voice, sorry=None):
@@ -88,6 +99,13 @@ def load(activity, voice, sorry=None):
logger.debug('Load bot: %s' % brain)
kernel = aiml.Kernel()
+
+ if brain['brain'] is None:
+ warning = _("Sorry, there is no free memory to load my " \
+ "brain. Close other activities and try once more.")
+ activity.face.say_notification(warning)
+ return
+
kernel.loadBrain(brain['brain'])
for name, value in brain['predicates'].items():
kernel.setBotPredicate(name, value)