You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This bug would be resolved if issue #230 was resolved. Filing it in case there is a fast fix for this specific issue.
When running robotpy test if the user code subscribes to changes via wpilib.SendableChooser.onChange and passes a python object that references third-party hardware, such as a rev.CANSparkMax, all tests after the first fail because a reference is held to the python object across tests. Later test fail when they reinstantiate hardware that is already held by the python object retained from the last test.
From the user perspective there is no feedback from the test about why the HW instances are being created twice. Indeed, the user code has no errors and runs fine on the first try.
I was going to suggest wrapping SendableChooser in a weakref.proxy before returning it to python user code and adding a gc.collect() to PyFrcPlugin.robot(). Those changes resolved the issue in the code this was found in. However in the included reproduction code those changes did not solve the problem.
import wpilib
import rev
import weakref
def no_reference_callback(value):
return
class MyRobot(wpilib.TimedRobot):
_motor: rev.CANSparkMax
_chooser: wpilib.SendableChooser
def robotInit(self):
self._motor = rev.CANSparkMax(1, rev.CANSparkMax.MotorType.kBrushless)
self._chooser = wpilib.SendableChooser()
#In the code this bug was found in, a weakref.proxy combined with an extra
#gc.collect at the end of pyfrc.test_support.pytest_plugin.py PyFrcPlugin.robot()
# was used to solve the bug. It does not appear to work in this reproduction.
#self._chooser = weakref.proxy(wpilib.SendableChooser())
self._chooser.onChange(self._chooserChanged)
# Not passing a reference to the python object in the callback will allow tests to
# complete normally
# self._chooser.onChange(no_reference_callback)
def _chooserChanged(self):
pass
The text was updated successfully, but these errors were encountered:
Problem description
This bug would be resolved if issue #230 was resolved. Filing it in case there is a fast fix for this specific issue.
When running
robotpy test
if the user code subscribes to changes viawpilib.SendableChooser.onChange
and passes a python object that references third-party hardware, such as a rev.CANSparkMax, all tests after the first fail because a reference is held to the python object across tests. Later test fail when they reinstantiate hardware that is already held by the python object retained from the last test.From the user perspective there is no feedback from the test about why the HW instances are being created twice. Indeed, the user code has no errors and runs fine on the first try.
I was going to suggest wrapping
SendableChooser
in aweakref.proxy
before returning it to python user code and adding agc.collect()
to PyFrcPlugin.robot(). Those changes resolved the issue in the code this was found in. However in the included reproduction code those changes did not solve the problem.Operating System
Windows
Installed Python Packages
Reproducible example code
The text was updated successfully, but these errors were encountered: