Skip to content

Issues with using stack.fork #10

Description

@muelleel

Hi, we have an Problem with the fork function of the stack.

We used the code from your example

# LEGO type:advanced slot:0 autostart

import runtime
import sys
import system

async def main(vm, stack):
    done = False 
    async def fork(): 
        print("Test") # replace with your code to be run in parallel 
        nonlocal done 
        done = True 
    stack.fork("fork", fork()) 
    print("test2")
    while not done: 
        yield 
    # at this point both operations will be complete 
    vm.stop()

def setup(rpc, system, stop):
    vm = runtime.VirtualMachine(rpc, system, stop, "hello_world")
    vm.register_on_start("main_on_start", main)
    return vm

The code exits immediatilly extits with following message:

Traceback (most recent call last):
  File "event_loop/event_loop.py", line 1, in step
  File "runtime/stack.py", line 1, in coro
  File "./projects/996/__init__.py", line 13, in main
AttributeError: 'Stack' object has no attribute 'fork'

Can you help with this? How can we execute multiple things simultaneously?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions