Skip to content
Snippets Groups Projects
Commit 34746823 authored by Stuart Gathman's avatar Stuart Gathman
Browse files

Use python locking to avoid busy wait.

parent baeddd9f
No related branches found
No related tags found
No related merge requests found
......@@ -2,10 +2,13 @@ import time
import logging
import urllib
import sqlite3
import thread
from datetime import datetime
log = logging.getLogger('milter.greylist')
_db_lock = thread.allocate_lock()
class Greylist(object):
def __init__(self,dbname,grey_time=10,grey_expire=4,grey_retain=36):
......@@ -35,6 +38,7 @@ class Greylist(object):
def check(self,ip,sender,recipient,timeinc=0):
"Return number of allowed messages for greylist triple."
_db_lock.acquire()
cur = self.conn.execute('begin immediate')
try:
cur.execute('''select firstseen,lastseen,cnt,umis from greylist where
......@@ -73,7 +77,9 @@ class Greylist(object):
where ip=? and sender=? and recipient=?''',
(now,now,0,None,ip,sender,recipient))
self.conn.commit()
finally: cur.close()
finally:
cur.close()
_db_lock.release()
return cnt
def close(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment