Skip to content

Conversation

@slonopotamus
Copy link

In case the loop doesn't do anything async, hub becomes unresponsive: it cannot stop program using central button, it doesn't react to stopping from the app. The only way to recover from such state is to power-cycle the hub. yield is a safety measure that ensures that hub has an opportunity to stop the program.

I've tested Mindstorms App 10.5.0 and this is what it produces for a program with empty infinite loop:

from runtime import VirtualMachine

# When program starts
async def stack_1(vm, stack):
    # Control forever
    while True:
        yield

def setup(rpc, system, stop):
    vm = VirtualMachine(rpc, system, stop, "zT3_XLSwxzq9a3X2HyM_")

    vm.register_on_start("dN8usIOJtd8aD0BgPcv-", stack_1)

    return vm

I haven't checked, but possibly other kinds of loops also need this.

In case the loop doesn't do anything async, hub becomes unresponsive: it cannot stop program using central button, it doesn't react to stopping from the app. The only way to recover from such state is to power-cycle the hub. `yield` is a safety measure that ensures that hub has an opportunity to stop the program.

I've tested Mindstorms App 10.5.0 and this is what it produces for a program with empty infinite loop:

```python
from runtime import VirtualMachine

# When program starts
async def stack_1(vm, stack):
    # Control forever
    while True:
        yield

def setup(rpc, system, stop):
    vm = VirtualMachine(rpc, system, stop, "zT3_XLSwxzq9a3X2HyM_")

    vm.register_on_start("dN8usIOJtd8aD0BgPcv-", stack_1)

    return vm
```

I haven't checked, but possibly other kinds of loops also need this.
@slonopotamus
Copy link
Author

slonopotamus commented Feb 25, 2023

UPD: To be more exact, Mindstorms checks if there is anything async inside the loop and only inserts yield if case there isn't. This also applies to other loops (repeat <N>, repeat <until>).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant