python - greenthreads doesn't run just after the spawn call -
i'm creating simple program uses eventlet greenthreads , cannot understand behavior. following example seems me thread runs when call .wait() method. read documentation , can't find method similar "start" method provided threading module. there similar method force thread run after creation (spawn call)?
python 2.7.6 (default, oct 26 2016, 20:30:19) [gcc 4.8.4] on linux2 type "help", "copyright", "credits" or "license" more information. >>> import eventlet >>> def test(): ... print("this test") ... >>> gth = eventlet.spawn(test) >>> >>> gth.wait() test >>>
tl;dr: need eventlet.sleep()
or wait useful, network.
observed behavior expected synthetic test. production code provides excessive opportunities running other greenthreads. in other words: it works similar os threads real code.
eventlet provides cooperative multitasking. every thread yields control others, giving other threads chance run. eventlet can patch system libraries yield when block.
please see https://stackoverflow.com/a/14227272/73957 more verbose explanation.
Comments
Post a Comment