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
{{ message }}
Repository navigation
[Bug] ForceSensor methods return <Async> instead of a value in an async program #2867
Describe the bug
Any ForceSensor method reterns <Async> instead of a value, when used in async mode.
Other sensors in the same situation work just fine.
To reproduce
Steps to reproduce the behavior:
frompybricks.pupdevicesimportColorSensor, ForceSensorfrompybricks.parametersimportColor, Portfrompybricks.toolsimportwait, run_taskfs=ForceSensor(Port.A)
cs=ColorSensor(Port.B)
asyncdeffoo():
returnawaitfs.distance(), awaitcs.color()
asyncdefmain():
data=awaitfoo()
print(data)
awaitwait(10)
print(fs.distance(), cs.color()) # may be any other ForceSensor methodrun_task(main())
Result:
The ForceSensor returns <Async> instead of a value
0.0 Color.NONE # Normal behaviour outside async
(<Async>, Color.NONE) # ForceSensor - bug behaviour, ColorSensor - normal behaviour
Expected behavior
ForceSensor methods to work in async mode.
Screenshots
There is a saying that a picture is worth a 1000 words. Screenshots really help to identify and solve problems.
My original program with double await now correctly fails:
('primehub', '4.1.1', 'ci-build-5124-v4.1.1-9-gd234acc42 on 2026-10-24')
Traceback (most recent call last):
File "issue_2867_explanation.py", line 26, in <module>
File "issue_2867_explanation.py", line 12, in main
TypeError: 'float' object isn't iterable
with single awaits: issue_2867_explanation_single_await
Activity
BertLindeman commentedon Oct 19, 2026
Hi,
Have tested on v4.1.0 firmware.
An updated script that shows some of the ForceSensor methods are double wrapped:
Current output:
laurensvalk commentedon Oct 20, 2026
Thanks for reporting. This is definitely a bug.
laurensvalk commentedon Oct 23, 2026
A fix is included in the latest release.
BertLindeman commentedon Oct 23, 2026
Running on
('primehub', '4.1.1', 'ci-build-5123-v4.1.1-6-gdf04d7220 on 2026-10-23')I still have this as output on my test script:
Maybe this v4.1.1-6 is not the version you meant?
laurensvalk commentedon Oct 24, 2026
Thank you. I misread. The blocks were missing await, which is now fixed, but it looks like this is a different issue.
BertLindeman commentedon Oct 24, 2026
reopen or do I add a new issue for "some forcesensor methods return "<Await>" in stead of the value"?
laurensvalk commentedon Oct 24, 2026
Found it. Should be fixed in a release next week. Thanks!
// pybricks.pupdevices.ForceSensor.force static mp_obj_t get_force(mp_obj_t self_in) { @@ -51,7 +51,7 @@ static mp_obj_t get_force(mp_obj_t self_in) { mp_obj_t result = pb_obj_new_fraction(force, 1000); return pb_type_async_return_result(result, &self->device_base.last_awaitable); } -static PB_DEFINE_CONST_TYPE_DEVICE_METHOD_OBJ(get_force_obj, LEGO_DEVICE_MODE_PUP_FORCE_SENSOR__FRAW, get_force); +static MP_DEFINE_CONST_FUN_OBJ_1(get_force_obj, get_force);laurensvalk commentedon Oct 24, 2026
Fixed via pybricks/pybricks-micropython@d234acc when it finishes building.
BertLindeman commentedon Oct 24, 2026
Ran
('primehub', '4.1.1', 'ci-build-5124-v4.1.1-9-gd234acc42 on 2026-10-24')Now shows:
Test script: block coded issue_2867_blocks
My original program with double await now correctly fails:
with single awaits: issue_2867_explanation_single_await
Result:
So fixed in work branch.
laurensvalk commentedon Oct 29, 2026
Fix has been released. Thanks for reporting and testing!
BertLindeman commentedon Oct 29, 2026
Confirm fixed on v4.1.2