本文整理汇总了Python中PriorityQueue.PriorityQueue.peek方法的典型用法代码示例。如果您正苦于以下问题:Python PriorityQueue.peek方法的具体用法?Python PriorityQueue.peek怎么用?Python PriorityQueue.peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.peek方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from PriorityQueue import PriorityQueue [as 别名]
# 或者: from PriorityQueue.PriorityQueue import peek [as 别名]
def main():
tasks = Dispenser(why_not)
time = 0
cmd, args = get_cmd( COMMANDS )
while cmd != QUIT_CMD:
if cmd == TICK_CMD:
time += 1
if not tasks.isEmpty():
current = tasks.peek()
current.time_left -= 1
if current.time_left == 0:
print( "\nTask '" + current.name + \
"' completed at time " + str( time ) + "." )
tasks.remove()
if not tasks.isEmpty():
print( "New task is '" + tasks.peek().name + "'." )
else:
print( "Nothing else to do." )
else:
print( "Nothing to do." )
elif cmd == ADD_CMD:
new_task = Task( args[ 0 ], int( args[ 1 ] ) )
tasks.insert( new_task )
print( "\nAdded. Current task is '" + tasks.peek().name + \
"'." )
else:
assert True, "PROGRAM ERROR"
cmd, args = get_cmd( COMMANDS )
print( "\nTerminating the simulation." )