Lock commands execution

So they can be used by separate threads
This commit is contained in:
moneromooo 2015-02-05 19:24:15 +00:00
parent 79de30a5dd
commit 8ff236176d
2 changed files with 23 additions and 1 deletions

View file

@ -45,6 +45,7 @@ def RunNextCommand(link,registered):
return return
try: try:
link=calltable[identity][0][0] link=calltable[identity][0][0]
Lock()
if registered: if registered:
calltable[identity][0][1](link,calltable[identity][0][2]) calltable[identity][0][1](link,calltable[identity][0][2])
else: else:
@ -53,6 +54,8 @@ def RunNextCommand(link,registered):
except Exception, e: except Exception, e:
log_error('RunNextCommand: Exception in action, continuing: %s' % str(e)) log_error('RunNextCommand: Exception in action, continuing: %s' % str(e))
del calltable[identity][0] del calltable[identity][0]
finally:
Unlock()
def Commands(link,cmd): def Commands(link,cmd):
if IsAdmin(link): if IsAdmin(link):
@ -159,7 +162,13 @@ def OnCommand(link,cmd,check_admin,check_registered):
elif 'registered' in c and c['registered']: elif 'registered' in c and c['registered']:
check_registered(link,c['function'],cmd,SendToProxy,"You must be registered with Freenode") check_registered(link,c['function'],cmd,SendToProxy,"You must be registered with Freenode")
else: else:
c['function'](link,cmd) Lock()
try:
c['function'](link,cmd)
except:
raise
finally:
Unlock()
else: else:
silent = False silent = False
if link.network.name in config.silent_invalid_commands: if link.network.name in config.silent_invalid_commands:
@ -174,9 +183,12 @@ def RunIdleFunctions(param=None):
if 'idle' in modules[module]: if 'idle' in modules[module]:
f=modules[module]['idle'] f=modules[module]['idle']
try: try:
Lock()
f(param) f(param)
except Exception,e: except Exception,e:
log_error("Exception running idle function %s from module %s: %s" % (str(f),module,str(e))) log_error("Exception running idle function %s from module %s: %s" % (str(f),module,str(e)))
finally:
Unlock()
def RunModuleHelpFunction(module,link): def RunModuleHelpFunction(module,link):
if module in modules: if module in modules:

View file

@ -14,6 +14,7 @@ import hashlib
import json import json
import httplib import httplib
import time import time
import threading
import math import math
import string import string
from decimal import * from decimal import *
@ -29,6 +30,8 @@ cached_tipbot_balance=None
cached_tipbot_unlocked_balance=None cached_tipbot_unlocked_balance=None
cached_tipbot_balance_timestamp=None cached_tipbot_balance_timestamp=None
core_lock = threading.Lock()
def GetPassword(name): def GetPassword(name):
try: try:
f = open('tipbot-password.txt', 'r') f = open('tipbot-password.txt', 'r')
@ -360,3 +363,10 @@ def GetNetworkByType(type):
return network return network
return None return None
def Lock():
return core_lock.acquire()
def Unlock():
core_lock.release()
return True