python - Are greenlets really useful by themselves? -
i'm having trouble conceptualizing big deal greenlets. understand how ability switch between running functions in same process open door world of possibilities; haven't come across examples of how solve problems standard python techniques cannot (other nested-functions-in-generators problem--which, honestly..."meh").
take this example greenlet's main page more complex way of doing this:
def test0(): print 12 print 56 print 34 i know it's superfluous example, seems long , short of greenlets can do. unless that of control-freak you have 1 decides when, where, , how every line of code in application executed, how test0 improved using greenlets? or take gui example (which interested me in greenlets in first place); it's shouldn't hard ponder strategy doesn't require while loop in process_commands, no?
i've seen some of cool things can done greenlets; in conjunction other dark sorcery implemented in package (e.g., stackless, gevent, etc.). those, greenlets aren't sufficient, requiring them subclass.
my question:
what real-world examples of how 1 can 1 use greenlets, themselves, enhance functionality of python? suspect answer lies in networking--which why don't understand. there others?
note example has explicitly woven prints 1 function. in real program, don't have 2 functions; have arbitrary number of functions, of them third-party libraries don't control, , rewriting code interleave statements not quite simple.
guis excellent example: letting event loop (which the way handle commands in practice, btw) suspend when there no events read, gui can remain interactive on same thread. if event loop had stop , wait user press key, gui freeze, because nothing telling os redraw window.
not i'm huge fan of gevent in particular; i'm placing bets on stdlib asyncio library. :) it's same idea really: when have work involves lot of waiting, let other code run in meantime.
Comments
Post a Comment