⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@dlech
Copy link
Member

@dlech dlech commented Jan 25, 2026

This is just for testing for now. This is probably the first step towards unbreaking USB on slow computers.

dlech added 2 commits January 24, 2026 18:29
Remove the USB tx timeout from all drivers. There currently isn't a way
to recover from a timeout, so it just breaks the connection. Instead,
now, e.g. print statements will block forever if an application
disappears without unsubscribing first. This can happen, e.g. if
someone closes the browser tab running Pybricks Code without
disconnecting USB first (either the cable or using the button in
Pybricks Code). This isn't ideal behavior, but we will address what to
do about that at a later time.
@dlech dlech force-pushed the usb-remove-timeout branch from 13eae02 to c8f6754 Compare January 25, 2026 00:29
@coveralls
Copy link

Coverage Status

coverage: 49.86%. remained the same
when pulling c8f6754 on dlech:usb-remove-timeout
into 3874930 on pybricks:master.

@dlech
Copy link
Member Author

dlech commented Jan 25, 2026

Here is a visual program for testing:

from pybricks.hubs import ThisHub
from pybricks.parameters import Color
from pybricks.tools import wait

hub = ThisHub()

while True:
    hub.light.on(Color.RED)
    print("Red")
    wait(100)
    
    hub.light.on(Color.GREEN)
    print("Green")
    wait(100)

The point is to see when the program stalls because of print() blocking forever.

A known way to do this is to run the program in Pybricks Code and then close the browser tab without disconnecting USB first.

It would be helpful to find any other ways we can get the program to stall like that.

@dlech
Copy link
Member Author

dlech commented Jan 25, 2026

It would be helpful to find any other ways we can get the program to stall like that.

I'll go first. 😄

With the program running and USB connected in one Pybricks Code tab, open another Pybricks Code tab. If you have an older version of Pybricks Code, this does a USB reset in the new tab that breaks the connection in the old tab and still managed to stall the print. This should be fixed in https://labs.pybricks.com though since we removed the USB reset already there.

It does mean that in our firmware though, we need to make sure to unsubscribe if someone does a USB reset as this doesn't seem to be happening currently.

@BertLindeman
Copy link
Contributor

Test 1

Test with this firmware ev3-firmware-build-4663-gitc8b82544.zip on EV3 in labs as app (after retries due to timeout #2467)

  • The program runs.
  • Then I hard stopped the app
  • program on EV3 runs on for ? a minute or so
  • then the program on the EV3 stops on "red"

Not very helpful I think.

Huh, but wait a minute:
Restarted the labs app and the program magically runs on without me doing anything.
So on to test 2 without stopping the program (so no retries due to timeouts)

Test 2

same firmware, same labs app with a continued running program.
As labs is running as app, to get another session, open one in chrome:
Press the usb connect button and connect to the same EV3.
Developer console:

sagas.ts:564 creating code completion worker
sagas.ts:209 Failed to claim USB interface: NetworkError: Failed to execute 'claimInterface' on 'USBDevice': Unable to claim interface.
i_ @ sagas.ts:209
python-worker.ts:71 starting Pyodide...
/logo192-labs.png:1  Failed to load resource: the server responded with a status of 404 ()
(index):1 Error while trying to use the following icon from the Manifest: https://labs.pybricks.com/logo192-labs.png (Download error or resource isn't a valid image)
python-worker.ts:87 copied dump_storage_movehub.py to emscripten fs
python-worker.ts:87 copied issue_2374.py to emscripten fs
python-worker.ts:87 copied issue_2418_color_receive_side.py to emscripten fs
python-worker.ts:87 copied issue_2418_color_send_side.py to emscripten fs
python-worker.ts:87 copied issue_2467.py to emscripten fs
python-worker.ts:87 copied issue_2467_david.py to emscripten fs
python-worker.ts:87 copied issue_2495_block.py to emscripten fs
python-worker.ts:87 copied issue_2533_multicontroller.py to emscripten fs
python-worker.ts:87 copied issue_2533_nocar_anyhub.py to emscripten fs
python-worker.ts:87 copied show_pc_connected.py to emscripten fs
pyodide.asm.js:1 Loading docstring_parser, jedi, parso, pybricks_jedi, pybricks, typing_extensions
pyodide.asm.js:1 Loaded docstring_parser, pybricks_jedi, parso, jedi, pybricks, typing_extensions
pyodide.asm.js:1 preloading pybricks_jedi...
pyodide.asm.js:1 preloading done.
python-worker.ts:156 Pyodide is ready.
sagas.ts:623 code completion engine is ready
sagas.ts:627 Handling USB toggle action, current state: usb.connection.state.disconnected
sagas.ts:627 Handling USB toggle action, current state: usb.connection.state.disconnected
sagas.ts:209 Failed to claim USB interface: NetworkError: Failed to execute 'claimInterface' on 'USBDevice': Unable to claim interface.
i_ @ sagas.ts:209

The program runs on happily.

@dlech
Copy link
Member Author

dlech commented Jan 25, 2026

sagas.ts:209 Failed to claim USB interface: NetworkError: Failed to execute 'claimInterface' on 'USBDevice': Unable to claim interface.

This is expected. We will eventually change it to catch this error and pop up a message that says that that the hub is already connected to another program right now.

Restarted the labs app and the program magically runs on without me doing anything.

This is also expected. When Pybricks Code restarts, it tries to automatically connect to USB, which unblocks what the program was hung up on.

@BertLindeman
Copy link
Contributor

Thanks David.

Great to have the EV3 on USB on labs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants