from itertools import islice
def integers(): # 2,3,4,...
n = 1
while True:
n += 1
yield n
def sieve(s):
x = next(s)
yield x
it = sieve(filter(lambda y: y % x, s))
while True: yield next(it)
print( list( islice(sieve(integers()),890,900) ))
# 390-400 0.11s 9.8MB
# 590-600 0.18s 10.2MB
# 890-900 0.34s 10.5MB
# 990-1000 **run-time error: signal: 25 (SIGXFSZ)**
ZnJvbSBpdGVydG9vbHMgaW1wb3J0IGlzbGljZQoKZGVmIGludGVnZXJzKCk6ICAgICMgMiwzLDQsLi4uCiAgICBuID0gMQogICAgd2hpbGUgVHJ1ZToKICAgICAgICBuICs9IDEKICAgICAgICB5aWVsZCBuCgpkZWYgc2lldmUocyk6CiAgICB4ID0gbmV4dChzKQogICAgeWllbGQgeAogICAgaXQgPSBzaWV2ZShmaWx0ZXIobGFtYmRhIHk6IHkgJSB4LCBzKSkKICAgIHdoaWxlIFRydWU6IHlpZWxkIG5leHQoaXQpCgpwcmludCggbGlzdCggaXNsaWNlKHNpZXZlKGludGVnZXJzKCkpLDg5MCw5MDApICkpIAogICMgMzkwLTQwMCAgIDAuMTFzICA5LjhNQgogICMgNTkwLTYwMCAgIDAuMThzIDEwLjJNQiAgICAgICAKICAjIDg5MC05MDAgICAwLjM0cyAxMC41TUIgICAgICAgCiAgIyA5OTAtMTAwMCAgICoqcnVuLXRpbWUgZXJyb3I6IHNpZ25hbDogMjUgKFNJR1hGU1opKio=
[6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997]