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

Server.forever doesn't work with async variables #132

Open
Synthetica9 opened this issue Jan 15, 2024 · 1 comment
Open

Server.forever doesn't work with async variables #132

Synthetica9 opened this issue Jan 15, 2024 · 1 comment

Comments

@Synthetica9
Copy link

Description

Server.forever doesn't work with async SharedPVs, probably due to this sleep:

https://github.com/mdavidsaver/p4p/blob/f5c96bad937fff57f5243f72b7fdb89a408d0f4a/src/p4p/server/__init__.py#L175

To reproduce:

Run the following server:

import time
from p4p.nt import NTScalar
from p4p.server import Server
from p4p.server.asyncio import SharedPV

pv = SharedPV(nt=NTScalar('d'), initial=0.0)

@pv.put
async def handle(pv, op):
    pv.post(op.value())
    op.done()

Server.forever(providers=[{'foo': pv}])

Then run pvput foo 12

Observed behaviour

pvput times out:

$ pvput foo 12
Old : 2024-01-15 04:27:05.880  0 
Put timeout

Expected behaviour

pvput succeeds and updates the value

@mdavidsaver
Copy link
Member

Indeed Server.forever() is not async, and is in p4p.server instead of p4p.server.asyncio.

In the short term you could instead do something like:

done = asyncio.Event()
# install signal handler to call done.set()
with Server(...):
    await done.wait()

In the longer term, I see the convenience of an async equivalent of Server.forever(). I am not immediately sure where to add it. async/await can't appear in src/p4p/server/__init__.py as long as py2.7 is supported. I am not sure it would be worthwhile to add p4p.server.asyncio.Server just to add one classmethod. Maybe a helper method p4p.server.asyncio.serve_forever()?

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

No branches or pull requests

2 participants