本文整理汇总了Python中eventlet.Queue.empty方法的典型用法代码示例。如果您正苦于以下问题:Python Queue.empty方法的具体用法?Python Queue.empty怎么用?Python Queue.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eventlet.Queue
的用法示例。
在下文中一共展示了Queue.empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_connection_pooling
# 需要导入模块: from eventlet import Queue [as 别名]
# 或者: from eventlet.Queue import empty [as 别名]
def test_connection_pooling(self):
with patch('swift.common.memcached.socket') as mock_module:
# patch socket, stub socket.socket, mock sock
mock_sock = mock_module.socket.return_value
# track clients waiting for connections
connected = []
connections = Queue()
errors = []
def wait_connect(addr):
connected.append(addr)
sleep(0.1) # yield
val = connections.get()
if val is not None:
errors.append(val)
mock_sock.connect = wait_connect
memcache_client = memcached.MemcacheRing(['1.2.3.4:11211'],
connect_timeout=10)
# sanity
self.assertEquals(1, len(memcache_client._client_cache))
for server, pool in memcache_client._client_cache.items():
self.assertEqual(2, pool.max_size)
# make 10 requests "at the same time"
p = GreenPool()
for i in range(10):
p.spawn(memcache_client.set, 'key', 'value')
for i in range(3):
sleep(0.1)
self.assertEqual(2, len(connected))
# give out a connection
connections.put(None)
# at this point, only one connection should have actually been
# created, the other is in the creation step, and the rest of the
# clients are not attempting to connect. we let this play out a
# bit to verify.
for i in range(3):
sleep(0.1)
self.assertEqual(2, len(connected))
# finish up, this allows the final connection to be created, so
# that all the other clients can use the two existing connections
# and no others will be created.
connections.put(None)
connections.put('nono')
self.assertEqual(2, len(connected))
p.waitall()
self.assertEqual(2, len(connected))
self.assertEqual(0, len(errors),
"A client was allowed a third connection")
connections.get_nowait()
self.assertTrue(connections.empty())
示例2: Interpreter
# 需要导入模块: from eventlet import Queue [as 别名]
# 或者: from eventlet.Queue import empty [as 别名]
class Interpreter(object):
'''
The class repsonsible for keeping track of the execution of the
statemachine.
'''
def __init__(self):
self.running = True
self.configuration = OrderedSet()
self.internalQueue = Queue()
self.externalQueue = Queue()
self.statesToInvoke = OrderedSet()
self.historyValue = {}
self.dm = None
self.invokeId = None
self.parentId = None
self.logger = None
def interpret(self, document, invokeId=None):
'''Initializes the interpreter given an SCXMLDocument instance'''
self.doc = document
self.invokeId = invokeId
transition = Transition(document.rootState)
transition.target = document.rootState.initial
transition.exe = document.rootState.initial.exe
self.executeTransitionContent([transition])
self.enterStates([transition])
def mainEventLoop(self):
while self.running:
enabledTransitions = None
stable = False
# now take any newly enabled null transitions and any transitions triggered by internal events
while self.running and not stable:
enabledTransitions = self.selectEventlessTransitions()
if not enabledTransitions:
if self.internalQueue.empty():
stable = True
else:
internalEvent = self.internalQueue.get() # this call returns immediately if no event is available
self.logger.info("internal event found: %s", internalEvent.name)
self.dm["__event"] = internalEvent
enabledTransitions = self.selectTransitions(internalEvent)
if enabledTransitions:
self.microstep(enabledTransitions)
# eventlet.greenthread.sleep()
eventlet.greenthread.sleep()
for state in self.statesToInvoke:
for inv in state.invoke:
inv.invoke(inv)
self.statesToInvoke.clear()
if not self.internalQueue.empty():
continue
externalEvent = self.externalQueue.get() # this call blocks until an event is available
if externalEvent.name == "cancel.invoke.%s" % self.dm.sessionid:
continue
self.logger.info("external event found: %s", externalEvent.name)
self.dm["__event"] = externalEvent
for state in self.configuration:
for inv in state.invoke:
if inv.invokeid == externalEvent.invokeid: # event is the result of an <invoke> in this state
self.applyFinalize(inv, externalEvent)
if inv.autoforward:
inv.send(externalEvent)
enabledTransitions = self.selectTransitions(externalEvent)
if enabledTransitions:
self.microstep(enabledTransitions)
# if we get here, we have reached a top-level final state or some external entity has set running to False
self.exitInterpreter()
def exitInterpreter(self):
statesToExit = sorted(self.configuration, key=exitOrder)
for s in statesToExit:
for content in s.onexit:
self.executeContent(content)
#.........这里部分代码省略.........
示例3: Interpreter
# 需要导入模块: from eventlet import Queue [as 别名]
# 或者: from eventlet.Queue import empty [as 别名]
class Interpreter(object):
'''
The class repsonsible for keeping track of the execution of the
statemachine.
'''
def __init__(self):
self.running = True
self.exited = False
self.cancelled = False
self.configuration = OrderedSet()
self.internalQueue = Queue()
self.externalQueue = Queue()
self.statesToInvoke = OrderedSet()
self.historyValue = {}
self.dm = None
self.invokeId = None
self.parentId = None
self.logger = None
def interpret(self, document, invokeId=None):
'''Initializes the interpreter given an SCXMLDocument instance'''
self.doc = document
self.invokeId = invokeId
transition = Transition(document.rootState)
transition.target = document.rootState.initial
transition.exe = document.rootState.initial.exe
self.executeTransitionContent([transition])
self.enterStates([transition])
def mainEventLoop(self):
while self.running:
enabledTransitions = None
stable = False
# now take any newly enabled null transitions and any transitions triggered by internal events
while self.running and not stable:
enabledTransitions = self.selectEventlessTransitions()
if not enabledTransitions:
if self.internalQueue.empty():
stable = True
else:
internalEvent = self.internalQueue.get() # this call returns immediately if no event is available
self.logger.info("internal event found: %s", internalEvent.name)
self.dm["__event"] = internalEvent
enabledTransitions = self.selectTransitions(internalEvent)
if enabledTransitions:
self.microstep(enabledTransitions)
# eventlet.greenthread.sleep()
eventlet.greenthread.sleep()
for state in self.statesToInvoke:
for inv in state.invoke:
inv.invoke(inv)
self.statesToInvoke.clear()
if not self.internalQueue.empty():
continue
externalEvent = self.externalQueue.get() # this call blocks until an event is available
# if externalEvent.name == "cancel.invoke.%s" % self.dm.sessionid:
# continue
# our parent session also might cancel us. The mechanism for this is platform specific,
if isCancelEvent(externalEvent):
self.running = False
continue
self.logger.info("external event found: %s", externalEvent.name)
self.dm["__event"] = externalEvent
for state in self.configuration:
for inv in state.invoke:
if inv.invokeid == externalEvent.invokeid: # event is the result of an <invoke> in this state
self.applyFinalize(inv, externalEvent)
if inv.autoforward:
inv.send(externalEvent)
enabledTransitions = self.selectTransitions(externalEvent)
if enabledTransitions:
self.microstep(enabledTransitions)
# if we get here, we have reached a top-level final state or some external entity has set running to False
self.exitInterpreter()
#.........这里部分代码省略.........