简体   繁体   English

动态增加 asyncio.Queue 的大小?

[英]Dynamically increase size of asyncio.Queue?

Is it possible to dynamically change (increase) max size of asyncio.Queue object when there are already items in the queue?当队列中已有项目时,是否可以动态更改(增加) asyncio.Queue对象的最大大小?

What side effects are expected if it is done by manipulating internal properties?如果通过操纵内部属性来完成,会产生什么副作用?

No, it is not possible.不,这是不可能的。 There is no method of asyncio.Queue to do this.没有asyncio.Queue方法来做到这一点。

To get a queue with a different size you need to create a new one and possibly transfer all items, or you could for example create a setup where you can alternate between two queues, allowing you to replace the one that is currently not in use.要获得不同大小的队列,您需要创建一个新队列并可能传输所有项目,或者您可以例如创建一个设置,您可以在两个队列之间交替,允许您替换当前未使用的队列。


If you decide to manipulate the internal state of the queue that is not accessible through its interface, you might get it to work now, but you can not rely on it to not break when there are any Python updates.如果您决定操作无法通过其接口访问的队列的内部状态,您现在可能会使其工作,但您不能依赖它在有任何 Python 更新时不会中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM