forked from indymedia/epicyon
Separate thread class
parent
687c4378da
commit
74629df5c0
31
posts.py
31
posts.py
|
@ -16,6 +16,7 @@ import shutil
|
||||||
import threading
|
import threading
|
||||||
import sys
|
import sys
|
||||||
import trace
|
import trace
|
||||||
|
from threads import threadWithTrace
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
@ -33,36 +34,6 @@ sendThreads = []
|
||||||
# stores the results from recent post sending attempts
|
# stores the results from recent post sending attempts
|
||||||
postLog = []
|
postLog = []
|
||||||
|
|
||||||
class threadWithTrace(threading.Thread):
|
|
||||||
def __init__(self, *args, **keywords):
|
|
||||||
threading.Thread.__init__(self, *args, **keywords)
|
|
||||||
self.killed = False
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
self.__run_backup = self.run
|
|
||||||
self.run = self.__run
|
|
||||||
threading.Thread.start(self)
|
|
||||||
|
|
||||||
def __run(self):
|
|
||||||
sys.settrace(self.globaltrace)
|
|
||||||
self.__run_backup()
|
|
||||||
self.run = self.__run_backup
|
|
||||||
|
|
||||||
def globaltrace(self, frame, event, arg):
|
|
||||||
if event == 'call':
|
|
||||||
return self.localtrace
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def localtrace(self, frame, event, arg):
|
|
||||||
if self.killed:
|
|
||||||
if event == 'line':
|
|
||||||
raise SystemExit()
|
|
||||||
return self.localtrace
|
|
||||||
|
|
||||||
def kill(self):
|
|
||||||
self.killed = True
|
|
||||||
|
|
||||||
def getPersonKey(username: str,domain: str,keyType='public'):
|
def getPersonKey(username: str,domain: str,keyType='public'):
|
||||||
"""Returns the public or private key of a person
|
"""Returns the public or private key of a person
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
__filename__ = "threads.py"
|
||||||
|
__author__ = "Bob Mottram"
|
||||||
|
__license__ = "AGPL3+"
|
||||||
|
__version__ = "0.0.1"
|
||||||
|
__maintainer__ = "Bob Mottram"
|
||||||
|
__email__ = "bob@freedombone.net"
|
||||||
|
__status__ = "Production"
|
||||||
|
|
||||||
|
import threading
|
||||||
|
import sys
|
||||||
|
import trace
|
||||||
|
|
||||||
|
class threadWithTrace(threading.Thread):
|
||||||
|
def __init__(self, *args, **keywords):
|
||||||
|
threading.Thread.__init__(self, *args, **keywords)
|
||||||
|
self.killed = False
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.__run_backup = self.run
|
||||||
|
self.run = self.__run
|
||||||
|
threading.Thread.start(self)
|
||||||
|
|
||||||
|
def __run(self):
|
||||||
|
sys.settrace(self.globaltrace)
|
||||||
|
self.__run_backup()
|
||||||
|
self.run = self.__run_backup
|
||||||
|
|
||||||
|
def globaltrace(self, frame, event, arg):
|
||||||
|
if event == 'call':
|
||||||
|
return self.localtrace
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def localtrace(self, frame, event, arg):
|
||||||
|
if self.killed:
|
||||||
|
if event == 'line':
|
||||||
|
raise SystemExit()
|
||||||
|
return self.localtrace
|
||||||
|
|
||||||
|
def kill(self):
|
||||||
|
self.killed = True
|
Loading…
Reference in New Issue