The stackless run queue is implicit and whenever a tasklet blocks (i.e.
when doing channel operations and sender/receiver isn't available), a
"runnable" tasklet from the run queue is fetched and switched to.
stackless.run() is a tool to suspend the current tasklet while there are
runnable tasklets in the queue.
You can achieve a similar effect by doing:
while stackless.runcount > 1:
    stackless.schedule()


On 22 June 2015 at 15:25, Anselm Kruis <a.kr...@science-computing.de> wrote:

> 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.html#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.html#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/9f2a496e6ba2cf9680e357451a8d75821d0ebb72/Stackless/demo/tracing.py?at=2.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 <temp....@gmail.com> 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 = name
>>>          self.ch = stackless.channel()
>>>          stackless.tasklet(self.fun)()
>>>
>>>      def __call__(self,val):
>>>          self.ch.send(val)
>>>
>>>      def fun(self):
>>>         while 1:
>>>           v = self.ch.receive()
>>>           print "hi" , v
>>>
>>>
>>> if __name__ == "__main__":
>>>      obj = A("sh")
>>>      obj(6)
>>> -----------------------------------------------------------------
>>>
>>> output:
>>> ----------
>>> hi 6
>>>
>>>
>>>
>>>
>>>
>>> thanks,
>>> ravi
>>>
>>
>> _______________________________________________
>> Stackless mailing list
>> Stackless@stackless.com
>> http://www.stackless.com/mailman/listinfo/stackless
>>
>>
> --
>  Dipl. Phys. Anselm Kruis                       science + computing ag
>  Senior Solution Architect                      Ingolstädter Str. 22
>  email a.kr...@science-computing.de             80807 München, 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
>
>
>
> _______________________________________________
> Stackless mailing list
> Stackless@stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>
_______________________________________________
Stackless mailing list
Stackless@stackless.com
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to