Open
Conversation
mdavidsaver
reviewed
Jan 31, 2025
| async def _run(self) -> None: | ||
| logging.info("Running server.") | ||
| try: | ||
| Server.forever(providers=[self.provider._provider]) |
Member
There was a problem hiding this comment.
asyncio code should not use Server.forever(), which is a convenience for threading code to park a main thread. It probably should have been added under Server.thread. I think it actually pre-dates my adding support for cothread/asyncio.
The doc. comment gives the basic template.
p4p/src/p4p/server/__init__.py
Lines 165 to 169 in 9040d4b
A direct equivalent with asyncio would replace the blocking sleep.
with Server(*args, **kws):
await asyncio.sleep(99999999) Since KeyboardInterrupt doesn't work with asyncio, a more complete version would handle signals to allow for a graceful shutdown. (an example)
with Server(*args, **kws):
done = asyncio.Event()
loop.add_signal_handler(signal.SIGINT, done.set)
loop.add_signal_handler(signal.SIGTERM, done.set)
await done.wait()
Author
There was a problem hiding this comment.
Ah okay that makes sense. The example works now.
8c94458 to
b698f52
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I can't get the async server to work. I think adding an example while troubleshooting this would be good.
Both
READ_PVandWRITE_PVcan be successfully set up andpvget'd, however I can't get the async handler to function. Thepvputtimes out, and after exiting the server we get the error:I was judging this was the recommended way to set up a server from asynciotest.py?