好吧,我是一名Java开发人员,他决定使用python 2.7
创建一个应用程序基本上我使用队列从UDP端口接收信息,另一个进程负责提取先前插入此队列的这些值。到目前为止,唯一的问题是,文档(https://docs.python.org/2/library/queue.html)说当目标无限队列时,基本上我们应该在实例化队列时发送参数< = 0(例如Queue.Queue(maxsize = 0)),但是当我的队列包含大约32766个值时,它会抛出/引发一个完整的异常..
有人可以告诉我原因吗?
while True:
try:
self.queue.put(valueToInsertIntoQueue, block=False)
break
except Full:
print('WHYYY? Queue is supposed to be infinite, at least until my memory blows...')
continue
回溯:
Traceback (most recent call last):
File "MyFile.py", line 71, in inserValueIntoQueue
self.queue.put(valueToInsertIntoQueue, block=False)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 155, in put
return self.put(obj, False)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/queues.py", line 102, in put
raise Full
Full
Plataform:
导入平台
platform.architecture()
('64bit','')
答案 0 :(得分:2)
http://bugs.python.org/issue8426
http://bugs.python.org/issue8237
很抱歉没有完全回答 - 我会评论,但我没有足够的声誉
编辑:我看了source code for multiprocessing queues。
Python中多处理队列中的值存储在Python Deque数据结构中。看一下underlying C source code for the deque,我注意到了deque的这种类型定义:
typedef struct {
PyObject_VAR_HEAD
block *leftblock;
block *rightblock;
Py_ssize_t leftindex; /* 0 <= leftindex < BLOCKLEN */
Py_ssize_t rightindex; /* 0 <= rightindex < BLOCKLEN */
size_t state; /* incremented whenever the indices move */
Py_ssize_t maxlen;
PyObject *weakreflist;
} dequeobject;
具体来说,请注意以下这一行:
Py_ssize_t maxlen;
根据this PEP,
引入了一个新类型Py_ssize_t,它与编译器的size_t类型大小相同,但是已签名。
所以,我的猜测是你的编译器的size_t类型是32位。带符号的32位整数的值范围在-32,768到32,767之间,上限是程序抛出异常的位置。
您是否有机会使用32位Python? :)