堆栈中的 get() 和 get_nowait() 有什么区别?

what is difference in get() and get_nowait() in stack?

我找不到 Stack 的这两个函数之间的区别。 get():- returns 个元素。 get_nowait() :- 也是 returns 元素。 那么是什么让他们与众不同呢??

不同的是一个挡住一个不挡。来自 docs:

Queue.get(block=True, timeout=None)

Remove and return an item from the queue. If optional args block is true and timeout is None (the default), block if necessary until an item is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. Otherwise (block is false), return an item if one is immediately available, else raise the Empty exception (timeout is ignored in that case).

Queue.get 如果 block 参数是 True 将阻塞,直到一个元素被推送到队列或超过给定的超时。

Queue.get_nowait()

Equivalent to get(False).

Queue.get_no_wait() 永远不会阻塞,但如果队列为空,则会 return Queue.Empty

堆栈实现也是如此。