Skip to content

Allow creating RM instance outside asyncio context. - #50

Merged
dmgav merged 17 commits into
bluesky:mainfrom
dmgav:fix-async
Apr 26, 2025
Merged

Allow creating RM instance outside asyncio context.#50
dmgav merged 17 commits into
bluesky:mainfrom
dmgav:fix-async

Conversation

@dmgav

@dmgav dmgav commented Apr 21, 2025

Copy link
Copy Markdown
Contributor

Implemented a feature, which allows to create instance of async RM outside asyncio context:

from bluesky_queueserver_api.zmq.aio import REManagerAPI
from bluesky.callbacks.best_effort import BestEffortCallback
import bluesky.plan_stubs as bps
import asyncio


if __name__ == "__main__":

    RM = REManagerAPI(
        zmq_control_addr="tcp://localhost:60615",
        zmq_info_addr="tcp://localhost:60625",
    )

    async def test():
        rep = await RM.status()
        print(f"{rep=}")

    f = asyncio.run_coroutine_threadsafe(test(), loop=RM.loop)
    f.result(timeout=None)

Now async RM may be easily instantiated using event loop created by Run Engine. Then RM object may be used from Bluesky plans to communicate with Queue Server.

    RE = RunEngine()
    RM = REManagerAPI(
        zmq_control_addr="tcp://localhost:60615",
        zmq_info_addr="tcp://localhost:60625",
        loop = RE.loop
    )

Motivation and Context

The feature was implemented to address #48 and may be useful for #49.

Summary of Changes for Release Notes

Fixed

Added

  • New parameter loop was added to async versions of REManagerAPI. The parameter may be used to instantiate the object outside asyncio context. For example, REManagerAPI may be instantiated directly Bluesky startup code using the event loop created by Bluesky Run Engine.

Changed

Removed

How Has This Been Tested?

Unit tests were added.

@dmgav
dmgav marked this pull request as draft April 21, 2025 22:46
@dmgav dmgav changed the title Fix async Allow creating RM instance outside asyncio context. Apr 22, 2025
@dmgav
dmgav marked this pull request as ready for review April 26, 2025 15:06
@dmgav
dmgav merged commit 351098a into bluesky:main Apr 26, 2025
@dmgav
dmgav deleted the fix-async branch April 26, 2025 15:06
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