Implement co-operative schduling

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
tarun2121
Posts: 9
Joined: Wed Oct 22, 2014 9:55 am

Implement co-operative schduling

Post by tarun2121 » Fri Nov 28, 2014 9:50 am

Hi all
I need to implement Co-operative scheduling in micropython environment. I am new to Python(& micropython). I tried it by using "yield". But I couldn't understand it accordingly. Following is the example what I want and waht I am getting.
Suppose I have two tasks, and 7 instructions each task.
T1
loop forever:
{
T11:
T12:
T13:
T14:
T15: yield to Task T2
T16:
T17:
}

AND

T2

loop forever:
{
T21:
T22:
T23:
T24:
T25: Yield to Task T1.
T26:
T27:
}

If I start my execution from T1. The sequence of execution should be [T11, T12, T13, T14, T15, T21, T22, T23, T24, T25, T16, T17, T11, T12, T13, T14, T15, T26, T27, T21, T22, T23, T24, T25, T16, T17, T11, ........ ]

But I am getting sequence as [T11, T12, T13, T14, T15, T21, T22, T23, T24, T25, T11, T12, T13, T14, T15, T21, T22, T23, T24, T25, T11, T12, T13, T14, T15, T21, T22, T23, T24, T25, .....]

I am switching from one task to another by using "yield" keyword. yield pauses the current execution sequence and takes control to generator object(where I am switching between tasks)
If anyone can help me with correct way?

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: Implement co-operative schduling

Post by Turbinenreiter » Fri Nov 28, 2014 10:16 am

We'd need the actual code to help.

tarun2121
Posts: 9
Joined: Wed Oct 22, 2014 9:55 am

Re: Implement co-operative schduling

Post by tarun2121 » Tue Dec 02, 2014 9:12 am

When I use generator.next() in micropython It gives error "generator object has no attribute 'next' ".
I used it in Python without any library import it works. what can be the issue and solution?

Architekt
Posts: 10
Joined: Wed Oct 15, 2014 8:59 am

Re: Implement co-operative schduling

Post by Architekt » Tue Dec 02, 2014 12:35 pm

tarun2121 wrote:When I use generator.next() in micropython It gives error "generator object has no attribute 'next' ".
I used it in Python without any library import it works. what can be the issue and solution?

Code: Select all

generator.next()
Is not in Python 3. Use:

Code: Select all

next(generator)

tarun2121
Posts: 9
Joined: Wed Oct 22, 2014 9:55 am

Re: Implement co-operative schduling

Post by tarun2121 » Wed Dec 03, 2014 9:58 am

Thanks.
It works.. !!

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: Implement co-operative schduling

Post by pfalcon » Wed Dec 03, 2014 11:48 pm

Everything was already implemented, please see http://forum.micropython.org/viewtopic.php?f=3&t=85
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply