Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow other entities than PASEOS to use event loop #48

Closed
johanos1 opened this issue Nov 23, 2022 · 0 comments · Fixed by #50
Closed

Allow other entities than PASEOS to use event loop #48

johanos1 opened this issue Nov 23, 2022 · 0 comments · Fixed by #50
Assignees
Labels
enhancement New feature or request tests Anything related to the tests user-facing Anything that users can interact with

Comments

@johanos1
Copy link
Collaborator

johanos1 commented Nov 23, 2022

Feature

Desired Behavior / Functionality

Current functionality: PASEOS decides when the async event loop is started and shut down. In particular, when an activity is performed, the async event loop is started and when the activity is closed, the event loop is too.

However, there may be other entities that also need access to the event loop, e.g., the communications layer that requires an event loop to be running in the background all the time. There are multiple issues with the current way of using async in PASEOS:

  1. If no activity is running and the communications layer is launched, the event loop is created from the communications layer and a RunTimeError "asyncio.run() cannot be called from a running event loop" occur.
  2. If the communications is launched as an activity, PASEOS will execute the task forever as the communications loop will not end. This will effectively block any other activity from being started.
  3. If the communications is forced to end, all the bells and whistles must be re-launched every time we want to perform communication in an activity.

Desired functionality: External entities should be able to access the event loop.

Here is a minimal example to reproduce the error:

import asyncio
import pykep as pk
import paseos
from paseos import ActorBuilder, SpacecraftActor

async def start_network_stuff():
    while True:
        await asyncio.sleep(1)
        print("outside job")

async def main_loop(sim):
    while True:
        # Start up network engine
        asyncio.gather(start_network_stuff())

        async def paseos_job(arg):
            await asyncio.sleep(1)
            print("paseos job")

        sim.register_activity("Job", paseos_job, power_consumption_in_watt=0)
        sim.perform_activity("Job")


earth = pk.planet.jpl_lp("earth")
sat = ActorBuilder.get_actor_scaffold(
    "sat1", SpacecraftActor, [10000000, 0, 0], pk.epoch(0)
)

sim = paseos.init_sim(sat)

asyncio.run(main_loop(sim))

What Needs to Be Done

Discuss potential changes in the architecture to allow for external usage of the event loop.

How Can It Be Tested

Via the above code for example and also via the already existing tests.

@johanos1 johanos1 changed the title Allow other entities than PASEOS to use async Allow other entities than PASEOS to use event loop Nov 23, 2022
@johanos1 johanos1 self-assigned this Nov 24, 2022
@gomezzz gomezzz added enhancement New feature or request tests Anything related to the tests user-facing Anything that users can interact with labels Nov 28, 2022
johanos1 added a commit that referenced this issue Nov 28, 2022
Allow other entities than PASEOS to use event loop #48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tests Anything related to the tests user-facing Anything that users can interact with
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants