[Tutor] looping generator
Alan Gauld
alan.gauld at btinternet.com
Thu Jan 7 13:16:20 EST 2016
On 07/01/16 17:02, richard kappler wrote:
> def dataRecv(connection):
> print 'receiving'
> while True:
> data = connection.recv(65536)
> while True:
> print "writing to data.in"
> f2.write(data)
> start = data.find('\x02')
> end = data.find('\x03')
> message = data[start+1:end]
> print "writing to messages.out"
> f3.write(message)
> yield message
There is something a bit weird going on here.
You are using yield to exit the function.
But the yield is inside an infinite loop with
no other break mechanism.
But that infinite loop is inside another infinite loop.
I don't see how you can ever complete the inner loop
so that it goes back to the outer loop.
Remember that when you use yield the function freezes.
Next time you call the function (in your outermost
while True loop) the function resumes just after the
yield - which is your innermost while loop.
How does it ever get back to the outer loop in
your function to read more data?
I think you need to rethink, and probably simplify,
the logic.
Or maybe I'm just missing something...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list