#from smokapi.system.serviceapi.daemonize import daemonize #from classes import Communicated #from smokapi.system.serviceapi.const import STATUS_OPERATING, LOG_INFO from threading import Thread, Lock class Communicated(object): def __init__(self): self.loglock = Lock() def log(self, ofile, text): print 'Acquiring lock' self.loglock.acquire() print 'Attempting to convert' if type(text) == unicode: text = text.encode('utf8', errors='strict') print 'Opening '+ofile with open(ofile, 'ab') as x: x.write(text+'\r\n') # \r\n is a RECORD SEPARATOR. text may contain \n print 'Closing '+ofile self.loglock.release() print 'Releasing lock' class Threaded(Thread): def __init__(self, sm): self.sm = sm Thread.__init__(self) def run(self): sm.log('ipc', u'threadspecific-slave') while True: pass #daemonize() sm = Communicated() #sm.setupIPC() Threaded(sm).start() #sm.preload() sm.log('main', u'communicated is operating') #sm.setStatus(STATUS_OPERATING) #sm.work() while True: pass