本文整理汇总了Python中Queue.LifoQueue.empty方法的典型用法代码示例。如果您正苦于以下问题:Python LifoQueue.empty方法的具体用法?Python LifoQueue.empty怎么用?Python LifoQueue.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue.LifoQueue
的用法示例。
在下文中一共展示了LifoQueue.empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _visit
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def _visit(self, node, pre_action=None, post_action=None):
"""Explore the connected component,"""
self.time = self.time + 1
self.dd[node] = self.time
self.color[node] = "GREY"
Q = LifoQueue()
Q.put(node) # node is GREY
if pre_action: # when Q.put
pre_action(node)
while not Q.empty():
source = Q.get() # GREY node is processed
for edge in self.graph.iteroutedges(source):
if self.color[edge.target] == "WHITE":
self.parent[edge.target] = source
self.dag.add_edge(edge)
self.time = self.time + 1
self.dd[edge.target] = self.time
self.color[edge.target] = "GREY"
Q.put(edge.target) # target is GREY
if pre_action: # when Q.put
pre_action(edge.target)
self.time = self.time + 1
self.ff[source] = self.time
self.color[source] = "BLACK"
if post_action: # source became BLACK
post_action(source)
示例2: _find_path_dfs
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def _find_path_dfs(self):
"""Finding augmenting paths in the residual network."""
parent = dict((node, None) for node in self.residual.iternodes())
# Capacity of found path to node.
capacity = {self.source: float("inf")}
Q = LifoQueue()
Q.put(self.source)
while not Q.empty():
node = Q.get()
for edge in self.residual.iteroutedges(node):
cap = edge.weight - self.flow[edge.source][edge.target]
if cap > 0 and parent[edge.target] is None:
parent[edge.target] = edge.source
capacity[edge.target] = min(capacity[edge.source], cap)
if edge.target != self.sink:
Q.put(edge.target)
else:
# Backtrack search and write flow.
target = self.sink
while target != self.source:
node = parent[target]
self.flow[node][target] += capacity[self.sink]
self.flow[target][node] -= capacity[self.sink]
target = node
return capacity[self.sink]
return 0
示例3: get_max_flow
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def get_max_flow(directed_graph, source, sink):
residual = {edge: edge.capacity for edges in directed_graph.values() for edge in edges}
flow_paths = []
def flow_path(path):
max_flow = float("inf")
for edge in path:
max_flow = min(max_flow, residual[edge])
for edge in path:
residual[edge] -= max_flow
flow_paths.append((max_flow, path))
bfs_queue = LifoQueue()
bfs_queue.put([])
while not bfs_queue.empty():
path = bfs_queue.get()
for edge in directed_graph[source if not path else path[-1].to_node]:
if residual[edge] > 0:
new_path = path[:]
new_path.append(edge)
if edge.to_node == sink:
flow_path(new_path)
else:
bfs_queue.put(new_path)
return flow_paths
示例4: DummyMessageHandler
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
class DummyMessageHandler(MessageHandler):
# TODO(steffen): locking
def __init__(self):
MessageHandler.__init__(self)
self._messages = LifoQueue()
self._devices = []
def register(self, device):
self._devices.append(device)
def read_message(self):
return self._messages.get()
def write_message_from_device(self, message):
self._messages.put(message)
def write_message(self, message):
for d in self._devices:
d.handle_message(message)
def has_messages(self):
for d in self._devices:
d.loop()
return not self._messages.empty()
def stop(self):
pass
示例5: Player
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
class Player(Fighter):
"""A Player character, inherits from Fighter
Returns: A player object
Functions: update, calcNewPos
Attributes: """
def __init__(self, name, imagelist, colour, screenwidth, screenheight, *groups):
super(Player, self).__init__(name, imagelist, colour, screenwidth, screenheight, *groups)
self.directionqueue = LifoQueue()
self.directiondict = {"up": False, "down": False, "left": False, "right": False}
self.hp = 10
def handlekeyevent(self, keyevent):
"""
Handle input and set direction or attacking based on rules
:param keyevent: (dict) Keyed on 'action' (e.g. 'keydown') and 'key' (e.g. 'up', 'fire')
:return:
"""
if keyevent["action"] == "keydown":
if keyevent["key"] in self.directiondict:
self.directiondict[keyevent["key"]] = True
self.directionqueue.put(keyevent["key"])
self.direction = keyevent["key"]
self.moving = True
elif keyevent["key"] == "fire":
self.attacking = True
elif keyevent["action"] == "keyup":
if keyevent["key"] in self.directiondict:
self.directiondict[keyevent["key"]] = False
elif keyevent["key"] == "fire":
self.attacking = False
if keyevent["key"] in self.directiondict and self.moving:
if not self.directiondict[self.direction]:
while not self.directionqueue.empty():
self.direction = self.directionqueue.get()
if self.directiondict[self.direction]:
break
if self.directionqueue.empty():
self.moving = False
for direction, active in self.directiondict.iteritems():
if active:
self.direction = direction
self.moving = True
示例6: stack
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
class stack():
def __init__(self):
self.s = LifoQueue()
def push(self, x):
self.s.put(x)
def pop(self):
return self.s.get()
def empty(self):
return self.s.empty()
示例7: dfSearch
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def dfSearch(start, actions, goalTest, depthLimit=False):
"""Depth-First Search"""
queue = LifoQueue()
queue.put(start)
while True:
if queue.empty():
return node
node = queue.get()
if goalTest(node):
return node
if (node.depth <= depthLimit) or (depthLimit is False):
queue = node.expand(queue, actions)
示例8: stackDFS
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def stackDFS(Graph, vroot):
"""
Depth First Search: stack version
"""
Stack=LifoQueue()
Stack.put(vroot)
while not Stack.empty():
iV=Stack.get()
print ("Visit :", iV)
Graph.setVisited(iV)
for jV in Graph.VertexList:
if Graph.Edges[iV,jV] and not Graph.Visited[jV]:
Stack.put(jV)
示例9: __init__
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def __init__(self,g,s):
queue = LifoQueue()
self.marked = {}
self.edgeTo = {}
self.s = s
for v in range(1,g.vertices()+1):
self.marked[v]=False
self.edgeTo[v]=-1
self.marked[s] = True
queue.put(s)
while not queue.empty():
v = queue.get()
for w in g.adj(v):
if not self.marked[w]:
queue.put(w)
self.marked[w] = True
self.edgeTo[w] = v
示例10: MenuAction
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
class MenuAction(object):
def __init__(self):
self.undo_commands = LifoQueue()
self.commands = defaultdict(Actions)
def set_command(self, item, activate, deactivate):
self.commands[item] = Actions(activate, deactivate)
def activate(self, item):
action = self.commands[item].activate
action.execute()
self.undo_commands.put(action)
def deactivate(self, item):
action = self.commands[item].deactivate
action.execute()
self.undo_commands.put(action)
def undo(self):
if not self.undo_commands.empty():
self.undo_commands.get().undo()
示例11: validTree
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def validTree(self, n, edges):
if edges == [] and n == 1:
return True
elif edges == []:
return False
visited = [-1 for i in range(0, n)]
father = [-1 for i in range(0, n)]
adjl = {i: [] for i in range(0, n)}
q = LifoQueue()
for edge in edges:
i = max(edge)
j = min(edge)
adjl[i].append(j)
adjl[j].append(i)
q.put(0)
visited[0] == 0
count = 0
while count < n:
while q.empty() == False:
u = q.get()
#print u
for i in adjl[u]:
if visited[i] == 1 and father[u] != i:
return False
if visited[i] == -1:
visited[i] = 0
father[i] = u
q.put(i)
visited[u] = 1
count += 1
try:
next = visited.index(-1)
print next
except:
return True
visited[next] = 0
q.put(next)
return True
示例12: inspect_cass_log
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
def inspect_cass_log(config):
cass_log_file = get_cass_log_file(config)
if not cass_log_file or not os.path.exists(cass_log_file):
return None
reader = BackwardsFileReader(cass_log_file)
lifo = LifoQueue()
last_line = reader.readline()
lifo.put(last_line)
while not re.match('^ERROR', last_line):
last_line = reader.readline()
if re.match('^\t', last_line):
lifo.put(last_line)
if re.match('^ERROR', last_line):
lifo.put(last_line)
if not last_line:
break
ret_str = ""
while not lifo.empty():
ret_str += lifo.get()
return ret_str
示例13: LifoQueue
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
from Queue import LifoQueue
q = LifoQueue()
for i in range(5):
q.put(i)
print "put: ", i
while True:
if q.empty():
break
else:
i = q.get(timeout = 1)
print "get :", i
示例14: mainframe
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
#.........这里部分代码省略.........
self.filenm = askopenfilename(filetypes=[("Supported Files","*.mp4;*.mkv;*.mpg;*.avi;*.mov"),("All Files","*.*")])
self.stream = False
self.play()
def streamopen(self):
self.streamnm = Dlog(self.parent)
if self.streamnm.result is not None:
s = str(self.streamnm)
else:
return
if s.startswith('http'):
self.stream = True
self.play()
else:
self.stream = False
showerror("Error","Incorrect Entry")
def play(self):
global fifofilename
if self.filenm is not None and self.filenm != "":
winid = self.videoFrame.winfo_id()
if self.mplayer_isrunning():
self.stop()
try:
self.paused = False
self.playbutton.configure(text="Pause")
if not self.stream:
self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.filenm],stdin=PIPE, stdout=PIPE)
else:
self.player_process = Popen(["mplayer","-fs","-slave","-quiet","-wid",str(winid),self.streamnm], stdin=PIPE, stdout=PIPE)
self.stdout_thread = Thread(target=self.enqueue_pipe, args=(self.player_process.stdout, self.q))
self.stdout_thread.daemon = True
self.stdout_thread.start()
self.emptypipe()
self.seekthread = Thread(target=self.seekbar_setup, args=())
self.seekthread.daemon = True
self.seekthread.start()
except:
showerror("Error","".join(["Couldn't play video:\n",str(sys.exc_info()[:])]))
def getvidtime(self):
if self.mplayer_isrunning():
self.command_player("get_time_length")
output = self.readpipe()
while "ANS_LENGTH" not in output:
output = self.readpipe()
if "ANS_LENGTH" in output:
return output.split('ANS_LENGTH=')[1]
else:
return 0
def playpause(self, event=None):
if self.player_process is None:
return
self.paused = not self.paused
if self.paused:
print "VIDEO IS PAUSED /B/RO"
self.playbutton.configure(text="Play")
else:
self.playbutton.configure(text="Pause")
self.command_player("pause")
def setwh(self,w,h):
self.videoFrame.configure(width=w, height=h)
def quit(self):
示例15: __init__
# 需要导入模块: from Queue import LifoQueue [as 别名]
# 或者: from Queue.LifoQueue import empty [as 别名]
#.........这里部分代码省略.........
ntiles=2**level # number of tiles per axis at this level
#mpp=cos(radians(self.loc[0]))*level0mpp/ntiles # actual resolution at this level
#coverage=width/(256*mpp) # how many tiles to cover screen width - in practice varies between ~2.4 and ~4.8
(cx,cy)=self.latlon2xy(self.loc[0], self.loc[1], level) # centre tile
#print self.loc, width, screensize.width, 1/ppm, ppm, level, ntiles, cx, cy
if __debug__: print "Desire imagery level", level
# We're using a Lifo queue, so as the user navigates the most important tiles are processed first.
# Should remove from the queue those tiles the user is probably not going to see again, but that's difficult so we don't.
# Display 6x6 tiles if available that cover the same area as 3x3 at the next higher level (this is to prevent weirdness when zooming in)
cx=2*(cx/2)
cy=2*(cy/2)
placements=[]
needed=set() # Placements at this level failed either cos imagery not available at this location/level or is pending layout
fetch=[]
seq=[(-2, 3), (-1, 3), (0, 3), (1, 3), (2, 3), (3, 3), (3, 2), (3, 1), (3, 0), (3, -1), (3, -2), (2, -2), (1, -2), (0, -2), (-1, -2), (-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, 2), (0, 2), (1, 2), (2, 2), (2, 1), (2, 0), (2, -1), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (0, 0)]
for i in range(len(seq)):
(x,y)=seq[i]
placement=self.getplacement(cx+x,cy+y,level, False) # Don't initiate fetch yet
if placement and placement.islaidout():
placements.append(placement)
else:
needed.add(((cx+x)/2,(cy+y)/2))
if 0<=x<=1 and 0<=y<=1:
fetch.append((cx+x,cy+y,level, True)) # schedule fetch of the centre 2x2 tiles
# Go up and get 5x5 tiles around the centre tile - but only draw them if higher-res imagery not (yet) available.
level-=1
cx/=2
cy/=2
fail2=True
if self.q.empty():
# If the queue is empty then the first (and low importance) tile starts processing immediately.
# So here we add the most important centre tile of 5x5 and ensure it starts processing.
placement=self.getplacement(cx,cy,level, True) # Initiate fetch
if placement:
fail2=False # Some imagery may be available at this level
if placement.islaidout() and (cx,cy) in needed:
placements.insert(0,placement) # Insert at start so drawn under higher-level
needed.remove((cx,cy))
while not self.q.empty():
time.sleep(0) # Allow worker thread to remove from queue
# First initiate fetch of higher-level imagery of centre 2x2
for args in fetch: self.getplacement(*args)
seq=[(1, -2), (0, -2), (-1, -2), (-2, -1), (-2, 0), (-2, 1), (-1, 2), (0, 2), (1, 2), (2, 1), (2, 0), (2, -1), (1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (0, 0)] # 5x5 with corners removed #, (0,3), (3,0), (0,-3), (-3,0)]
for i in range(len(seq)):
(x,y)=seq[i]
placement=self.getplacement(cx+x,cy+y,level, True) # Initiate fetch
if placement:
fail2=False # Some imagery may be available at this level
if placement.islaidout() and (abs(x)>1 or abs(y)>1 or (cx+x,cy+y) in needed):
placements.insert(0,placement) # Insert at start so drawn under higher-level
while fail2 and level>levelmin:
# No imagery available at all at higher level. Go up and get 3x3 tiles around the centre tile.
level-=1
cx/=2
cy/=2
seq=[(1, -1), (0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (0, 0)]
for i in range(len(seq)):
(x,y)=seq[i]
placement=self.getplacement(cx+x,cy+y,level, True)
if placement: