diff --git a/tipbot/command_manager.py b/tipbot/command_manager.py index 446e8cd..489d751 100644 --- a/tipbot/command_manager.py +++ b/tipbot/command_manager.py @@ -45,6 +45,7 @@ def RunNextCommand(link,registered): return try: link=calltable[identity][0][0] + Lock() if registered: calltable[identity][0][1](link,calltable[identity][0][2]) else: @@ -53,6 +54,8 @@ def RunNextCommand(link,registered): except Exception, e: log_error('RunNextCommand: Exception in action, continuing: %s' % str(e)) del calltable[identity][0] + finally: + Unlock() def Commands(link,cmd): if IsAdmin(link): @@ -159,7 +162,13 @@ def OnCommand(link,cmd,check_admin,check_registered): elif 'registered' in c and c['registered']: check_registered(link,c['function'],cmd,SendToProxy,"You must be registered with Freenode") else: - c['function'](link,cmd) + Lock() + try: + c['function'](link,cmd) + except: + raise + finally: + Unlock() else: silent = False if link.network.name in config.silent_invalid_commands: @@ -174,9 +183,12 @@ def RunIdleFunctions(param=None): if 'idle' in modules[module]: f=modules[module]['idle'] try: + Lock() f(param) except Exception,e: log_error("Exception running idle function %s from module %s: %s" % (str(f),module,str(e))) + finally: + Unlock() def RunModuleHelpFunction(module,link): if module in modules: diff --git a/tipbot/utils.py b/tipbot/utils.py index 827802f..21f7c92 100644 --- a/tipbot/utils.py +++ b/tipbot/utils.py @@ -14,6 +14,7 @@ import hashlib import json import httplib import time +import threading import math import string from decimal import * @@ -29,6 +30,8 @@ cached_tipbot_balance=None cached_tipbot_unlocked_balance=None cached_tipbot_balance_timestamp=None +core_lock = threading.Lock() + def GetPassword(name): try: f = open('tipbot-password.txt', 'r') @@ -360,3 +363,10 @@ def GetNetworkByType(type): return network return None +def Lock(): + return core_lock.acquire() + +def Unlock(): + core_lock.release() + return True +