Message91428
Here's a simple coroutine that works perfectly in Python 2.6 but seems
to let Py3.1 enter an infinite loop that ends up eating all memory.
-----------------
def printing_sink():
"A simple sink that prints the received values."
while True:
print( (yield) )
def chunker(chunk_size, target):
"""Receives single items and forwards chunks of a fixed size.
Usage example:
>>> sink = printing_sink()
>>> next(sink)
>>> cr = chunker(4, sink)
>>> next(cr)
>>> for i in range(8):
... cr.send(i)
[0, 1, 2, 3]
[4, 5, 6, 7]
>>> cr.close()
"""
while True:
target.send([ (yield) for i in range(chunk_size) ])
if __name__ == '__main__':
import doctest
doctest.testmod()
-----------------
Fails on:
Python 3.1 (r31:73572, Jun 28 2009, 21:07:35)
[GCC 4.3.2] on linux2
Works on:
Python 2.6.2 (r262:71600, Apr 17 2009, 11:29:30)
[GCC 4.3.2] on linux2
The problem seems to be the list comprehension. When I replace it with a
normal for-loop, it works perfectly. |
|
Date |
User |
Action |
Args |
2009-08-09 14:09:45 | scoder | set | recipients:
+ scoder |
2009-08-09 14:09:45 | scoder | set | messageid: <1249826985.41.0.2934011008.issue6673@psf.upfronthosting.co.za> |
2009-08-09 14:09:43 | scoder | link | issue6673 messages |
2009-08-09 14:09:42 | scoder | create | |
|