Comments (2)
Thanks for the detailed reply, thats' really helpful, and I tried to use async for to handle the received data, it works!
from caproto.
Thanks for reporting this. There's an underlying bug causing that message, but also an issue with the code you have provided.
Suggestions for your code
In your code, add_callback(f)
happens and start
returns almost immediately. That means that the closure f
gets garbage collected (along with the context and everything else).
You need to keep that function alive for a time period, such as adding an await asyncio.sleep(5)
to sleep for 5 seconds after you add the callback.
Alternatively, you might consider using the async with
and async for
syntax which is a bit more ergonomic than using callbacks. See an example here:
caproto/caproto/examples/asyncio_client_simple.py
Lines 36 to 40 in c31ecf3
async def start():
ctx = Context()
(array_data,) = await ctx.get_pvs("{pv_name}")
sub = array_data.subscribe()
responses = []
def f(sub, response):
print("Received response from", sub.pv.name)
responses.append(response)
token = sub.add_callback(f)
await asyncio.sleep(10)
or
async def start():
ctx = Context()
(array_data,) = await ctx.get_pvs("{pv_name}")
responses = []
async with array_data.subscribe() as sub:
async for value in sub:
print("Received response from", sub.pv.name, value)
responses.append(value)
The bug you helped uncover (re-uncover?)
The conversion of the threaded client to asyncio was never fully vetted. The background of the caproto async client issue that needs resolving is:
CallbackHandler
has a synchronousremove_callback
method:caproto/caproto/asyncio/client.py
Line 1907 in 57e0c56
- When your callback function gets garbage collected,
remove_callback
is automatically called as in here:caproto/caproto/asyncio/client.py
Line 1888 in 57e0c56
- However, the subclass
Subscription
reimplements (!)remove_callback
as async (the horror...):caproto/caproto/asyncio/client.py
Line 2122 in 57e0c56
- This means that garbage-collected Subscription callbacks will call the subclassed async method but never await them
I'd have to dive deeper to figure out if reimplementing CallbackHandler
to be async or decoupling Subscription
from the superclass would be better.
from caproto.
Related Issues (20)
- Caproto incompatibility with Python 3.11 HOT 4
- Deprecate/remove/fix examples which have getters
- Array slice channel filter works intermittently when used with camonitor HOT 2
- Repository links for Caproto-written IOCs? HOT 6
- CI: deprecated GHA usage of `set-output` needs resolving in docs workflow
- Add logo to documentation HOT 1
- Resource leak in caproto.threading.pyepics_compat HOT 3
- Python 3.12: 0-dim memory has no length
- caproto IOCs on Windows Python 3.12 have issues
- Implementing Motor controller IOC, is there a hook for a home action? HOT 1
- Help please, Cannot figure out how to pass parameters to SubGroup.. HOT 2
- Adding a ZMQ backend HOT 2
- Search does not work in documentation
- Python 3.12: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated HOT 1
- disconnect task not awaited
- Server traceback when reading a float HOT 3
- Failed to send beacon error HOT 6
- add date to logs HOT 2
- CAproto asyncio client going into endless loop on teardown when used with pytest HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from caproto.