Re: python program without stackless.run()
Anselm Kruis <[email protected]> Mon, 22 Jun 2015 17:25:16 +0200
| Newsgroups | gmane.comp.python.stackless |
|---|---|
| Message-ID | <[email protected]> |
Hi, I'm not so firm with the channel code, but I think it is fairly simple = to explain. Have a look at the documentation of the tasklet life cycle: = https://stackless.readthedocs.org/en/2.7-slp/library/stackless/tasklets.htm= l#tasklet-life-cycle As you can see, tasklet can become "current" without a running = scheduler. At the end of this section there is a simplified = documentation of the internal working of the stackless.run() function. = It does not enter a tasklet into the scheduler queue and it is not the = only way to switch tasklets. Your example uses 2 tasklets: 1. the main tasklet 2. the tasklet "self.fun" The line "stackless.tasklet(self.fun)()" creates and schedules tasklet = fun(). Then the main tasklet sends a message to through the channel self.ch. = This causes stackless to change the state of the main tasklet to = "blocked on channel" (See = https://stackless.readthedocs.org/en/2.7-slp/library/stackless/channels.htm= l#channel.send = "If no other tasklet is already receiving on the channel, the sender = will be blocked."). At the same moment the next tasklet on the schedule = queue, that is tasklet "self.fun" becomes "current". It receives the = message from the channel self.ch. This changes the state of the main = tasklet from "blocked on channel" to "scheduled". Then tasklet self.fun = runs to the end of method self.fun and terminates. This again triggers = the scheduler and now the main tasklet becomes current again. To observe the details, you may want to study the tracing example at https://bitbucket.org/stackless-dev/stackless/src/9f2a496e6ba2cf9680e357451= a8d75821d0ebb72/Stackless/demo/tracing.py?at=3D2.7-slp Regards Anselm Am 22.06.2015 um 13:55 schrieb temp sha: > hi, > > any help in understanding the program will be highly appreciated. > as per the stackless documentation stackless.run() is must > to start a scheduler. then how come the below program runs > the tasklet "fun" without stackless.run() call? > > > thanks in advance. > > > On Fri, Jun 19, 2015 at 2:36 AM, temp sha <[email protected]> wrote: >> Hi, >> >> I could not understand how the below program executes function "fun" >> without calling stackless.run() in the program? Here "fun" runs as a >> tasklet and as per my knowledge for that stackless.run() is must. >> >> >> >> ----------------------------------------------------------------- >> import stackless >> >> class A: >> def __init__(self,name): >> self.name =3D name >> self.ch =3D stackless.channel() >> stackless.tasklet(self.fun)() >> >> def __call__(self,val): >> self.ch.send(val) >> >> def fun(self): >> while 1: >> v =3D self.ch.receive() >> print "hi" , v >> >> >> if __name__ =3D=3D "__main__": >> obj =3D A("sh") >> obj(6) >> ----------------------------------------------------------------- >> >> output: >> ---------- >> hi 6 >> >> >> >> >> >> thanks, >> ravi > > _______________________________________________ > Stackless mailing list > [email protected] > http://www.stackless.com/mailman/listinfo/stackless > -- = Dipl. Phys. Anselm Kruis science + computing ag Senior Solution Architect Ingolst=E4dter Str. 22 email [email protected] 80807 M=FCnchen, Germany phone +49 89 356386 874 fax 737 www.science-computing.de -- = Vorstandsvorsitzender/Chairman of the board of management: Gerd-Lothar Leonhart Vorstand/Board of Management: Dr. Bernd Finkbeiner, Dr. Arno Steitz Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board: Philippe Miltin Sitz/Registered Office: Tuebingen Registergericht/Registration Court: Stuttgart Registernummer/Commercial Register No.: HRB 382196