本文整理汇总了Python中DIRAC.Core.Utilities.LockRing.LockRing._openAll方法的典型用法代码示例。如果您正苦于以下问题:Python LockRing._openAll方法的具体用法?Python LockRing._openAll怎么用?Python LockRing._openAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.Core.Utilities.LockRing.LockRing
的用法示例。
在下文中一共展示了LockRing._openAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from DIRAC.Core.Utilities.LockRing import LockRing [as 别名]
# 或者: from DIRAC.Core.Utilities.LockRing.LockRing import _openAll [as 别名]
def run( self ):
""" task execution
reads and executes ProcessTask :task: out of pending queue and then pushes it
to the results queue for callback execution
:param self: self reference
"""
## start watchdog thread
self.__watchdogThread = threading.Thread( target = self.__watchdog )
self.__watchdogThread.daemon = True
self.__watchdogThread.start()
## http://cdn.memegenerator.net/instances/400x/19450565.jpg
if LockRing:
# Reset all locks
lr = LockRing()
lr._openAll()
lr._setAllEvents()
## zero processed task counter
taskCounter = 0
## zero idle loop counter
idleLoopCount = 0
## main loop
while True:
## draining, stopEvent is set, exiting
if self.__stopEvent.is_set():
return
## clear task
self.task = None
## read from queue
try:
task = self.__pendingQueue.get( block = True, timeout = 10 )
except Queue.Empty:
## idle loop?
idleLoopCount += 1
## 10th idle loop - exit, nothing to do
if idleLoopCount == 10:
return
continue
## toggle __working flag
self.__working.value = 1
## save task
self.task = task
## reset idle loop counter
idleLoopCount = 0
## process task in a separate thread
self.__processThread = threading.Thread( target = self.__processTask )
self.__processThread.start()
## join processThread with or without timeout
if self.task.getTimeOut():
self.__processThread.join( self.task.getTimeOut()+10 )
else:
self.__processThread.join()
## processThread is still alive? stop it!
if self.__processThread.is_alive():
self.__processThread._Thread__stop()
## check results and callbacks presence, put task to results queue
if self.task.hasCallback() or self.task.hasPoolCallback():
if not self.task.taskResults() and not self.task.taskException():
self.task.setResult( S_ERROR("Timed out") )
self.__resultsQueue.put( task )
## increase task counter
taskCounter += 1
self.__taskCounter = taskCounter
## toggle __working flag
self.__working.value = 0
示例2: run
# 需要导入模块: from DIRAC.Core.Utilities.LockRing import LockRing [as 别名]
# 或者: from DIRAC.Core.Utilities.LockRing.LockRing import _openAll [as 别名]
def run( self ):
""" task execution
reads and executes ProcessTask :task: out of pending queue and then pushes it
to the results queue for callback execution
:param self: self reference
"""
## start watchdog thread
print "PID:%s PPID:%s Started WorkingProcess...." % (os.getpid(), os.getppid())
self.__watchdogThread = threading.Thread( target = self.__watchdog )
self.__watchdogThread.daemon = True
self.__watchdogThread.start()
print "PID:%s PPID:%s started watchdogThread.." % (os.getpid(), os.getppid())
## http://cdn.memegenerator.net/instances/400x/19450565.jpg
if LockRing:
# Reset all locks
lr = LockRing()
lr._openAll()
lr._setAllEvents()
## zero processed task counter
taskCounter = 0
## zero idle loop counter
idleLoopCount = 0
## main loop
while True:
## draining, stopEvent is set, exiting
if self.__stopEvent.is_set():
return
## clear task
self.task = None
## read from queue
try:
print "PID:%s PPID:%s Will try to GET from Pending Queue..." % (os.getpid(), os.getppid())
task = self.__pendingQueue.get( block = True, timeout = 5 ) # timeout changed from 10
print "PID:%s PPID:%s GOT a task from pending queue.." % (os.getpid(), os.getppid())
except Queue.Empty:
## idle loop?
idleLoopCount += 1
## 10th idle loop - exit, nothing to do
if idleLoopCount == 2: # changed from 10
print "PID:%s PPID:%s Tried 10 times to get something, exiting..."% (os.getpid(), os.getppid())
return
continue
## toggle __working flag
self.__working.value = 1
## save task
self.task = task
## reset idle loop counter
idleLoopCount = 0
## process task in a separate thread
self.__processThread = threading.Thread( target = self.__processTask )
self.__processThread.start()
print "PID:%s PPID:%s started process Thread..." % (os.getpid(), os.getppid())
## join processThread with or without timeout
if self.task.getTimeOut():
print "WILL WAIT FOR JOIN(timeout)"
self.__processThread.join( self.task.getTimeOut()+10 )
else:
print "WILL WAIT FOR JOIN"
self.__processThread.join()
## processThread is still alive? stop it!
if self.__processThread.is_alive():
self.__processThread._Thread__stop()
print "MUST FORCE-STOP PROCESS THREAD"
print "PID:%s PPID:%s Process thread done..."% (os.getpid(), os.getppid())
## check results and callbacks presence, put task to results queue
if self.task.hasCallback() or self.task.hasPoolCallback():
if not self.task.taskResults() and not self.task.taskException():
self.task.setResult( S_ERROR("Timed out") )
print ">>>TIMED OUT!!!!"
self.__resultsQueue.put( task )
print "ResultsQueue = %s " % self.__resultsQueue.qsize()
## increase task counter
taskCounter += 1
self.__taskCounter = taskCounter
## toggle __working flag
self.__working.value = 0
示例3: run
# 需要导入模块: from DIRAC.Core.Utilities.LockRing import LockRing [as 别名]
# 或者: from DIRAC.Core.Utilities.LockRing.LockRing import _openAll [as 别名]
def run( self ):
"""
Task execution
Reads and executes ProcessTask :task: out of pending queue and then pushes it
to the results queue for callback execution.
:param self: self reference
"""
## start watchdog thread
self.__watchdogThread = threading.Thread( target = self.__watchdog )
self.__watchdogThread.daemon = True
self.__watchdogThread.start()
## http://cdn.memegenerator.net/instances/400x/19450565.jpg
if LockRing:
# Reset all locks
lr = LockRing()
lr._openAll()
lr._setAllEvents()
## zero processed task counter
taskCounter = 0
## zero idle loop counter
idleLoopCount = 0
## main loop
while True:
## draining, stopEvent is set, exiting
if self.__stopEvent.is_set():
return
## clear task
self.task = None
## read from queue
try:
task = self.__pendingQueue.get( block = True, timeout = 10 )
except Queue.Empty:
## idle loop?
idleLoopCount += 1
## 10th idle loop - exit, nothing to do
if idleLoopCount == 10 and not self.__keepRunning:
return
continue
## toggle __working flag
self.__working.value = 1
## save task
self.task = task
## reset idle loop counter
idleLoopCount = 0
## process task in a separate thread
self.__processThread = threading.Thread( target = self.__processTask )
self.__processThread.start()
timeout = False
noResults = False
## join processThread with or without timeout
if self.task.getTimeOut():
self.__processThread.join( self.task.getTimeOut()+10 )
else:
self.__processThread.join()
## processThread is still alive? stop it!
if self.__processThread.is_alive():
self.__processThread._Thread__stop()
self.task.setResult( S_ERROR( errno.ETIME, "Timed out" ) )
timeout = True
# if the task finished with no results, something bad happened, e.g.
# undetected timeout
if not self.task.taskResults() and not self.task.taskException():
self.task.setResult( S_ERROR("Task produced no results") )
noResults = True
## check results and callbacks presence, put task to results queue
if self.task.hasCallback() or self.task.hasPoolCallback():
self.__resultsQueue.put( task )
if timeout or noResults:
# The task execution timed out, stop the process to prevent it from running
# in the background
time.sleep( 1 )
os.kill( self.pid, signal.SIGKILL )
return
## increase task counter
taskCounter += 1
self.__taskCounter = taskCounter
## toggle __working flag
self.__working.value = 0