[Microbit-Python] Game API objects I want

Jonathan Austin Jonathan.Austin at arm.com
Fri Oct 9 14:20:33 CEST 2015


> On 9 Oct 2015, at 05:04, Larry Hastings <larry at hastings.org> wrote:
>
>>
>> Joe has a Fiber scheduler in there, and it might be possible just to break out
>> bits from that.
>>
>
> I don't think I have access to that repository.

Hmm. Nicholas, Joe - is there a reason for that?

>
> Unless they're using the terminology in a different way, a Fiber is a completely unrelated concept to an event scheduler.  It's a user-scheduled thread, or a continuation, kind of like Python's "yield”.

I’ll let Joe comment more as he wrote all this - you’re right of course that the fibres alone aren’t going to get you the timed events, but I thought that along with the scheduler was a way to request that some work got done in a fiber after some time.

I had a poke though, and can’t immediately see that… What I’d like is something that can do:

fibersched.schedule_work(&work_callback, delay);
fibersched.recurring_work(&work_callback, period);

But instead it looks like the expected approach is to do something more like spawn a fiber and then sleep (which sleeps gracefully assuming you’re not in interrupt context), or spawn a fiber that waits for an event on the bus…

Joe - what’s the ‘right’ way to do that in the runtime at the moment?

>> Failing that, mbed has a Ticker and a Timeout class,
>>
>>
>> https://developer.mbed.org/handbook/Ticker
>> https://developer.mbed.org/handbook/Timeout
>
> These are also not-exactly related.  Those are both interrupt-driven callback functions.  Theoretically they could be mis-used for this ability.  But note the provisos: "no blocking code", "no print / malloc".  I suspect it's impossible to do anything useful in Python in an ISR.
>

Right, the way people usually build something like the scheduler you describe is to use these  classes to schedule work that gets done in the main thread, so those provisos don’t matter - IE you use the ticker/timeout to adding things to a work queue.

there’s a nice writeup that implements this on mbed here:
https://developer.mbed.org/users/AjK/notebook/regarding-interrupts-use-and-blocking/

J
>
> /arry
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit


________________________________

-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.



More information about the Microbit mailing list