capnproto / pycapnp

Cap'n Proto serialization/RPC system - Python bindings
BSD 2-Clause "Simplified" License
458 stars 125 forks source link

warning when serializing data in a callback #314

Closed CruxDevStuff closed 1 year ago

CruxDevStuff commented 1 year ago

I'm polling a sensor every 50ms which triggers a callback that publishes the sensor packet.

    accel = frame.accelerometer
    gyro = frame.gyroscope
    imu_msg.accel = [float(accel.x), float(accel.y), float(accel.z)]
    imu_msg.gyro = [float(gyro.x), float(gyro.y), float(gyro.z)]
    packet = imu_msg.to_bytes() <----- Here
    imu_publisher.put(packet)

Even though the code executes just fine(no memory leaks), I'm getting this warning:

_UserWarning: This message has already been written once. Be very careful that you're not setting Text/Struct/List fields more than once, since that will cause memory leaks (both in memory and in the serialized data). You can disable this warning by calling the clear_write_flag method of this object after every write. packet = imu_msg.tobytes()

Is this unintended behaviour(just ignore the warning ?) or is there another way to do this properly ?