Python Forum
example code for a coroutine generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
example code for a coroutine generator
#3
(Feb-06-2017, 05:18 AM)nilamo Wrote: Does that actually use coroutines anywhere, though?  It just looks like generators to me.

numbers are sent to it, one at a time.  numbers are received from it, one at a time.  send it a None and it does nothing with it (yeah, not much different than send a 0 value).  but this is using the send method.  i personally don't like the asymmetry.  but i don't see an easy way to make it symmetrical in python.

i do wonder about how python figures it to be a coroutine and blocks the initial call.  i can envision code that can dynamically decide whether to do yield, or not, and accept sent data, or not.  there is also the issue of using a proxy generator (a function to do the yield() and/or send() call for you).  this stuff was complex enough in C.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
RE: example code for a coroutine generator - by Skaperen - Feb-06-2017, 08:20 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020