Skip to content

pydfu: fix windows stdout.flush issue on python 3.6 #4164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

andrewleech
Copy link
Contributor

There appears to be an issue with cpython >= 3.6 sys.stdout.flush() on windows as used in pydfu.

File: firmware.dfu
    b'DfuSe' v1, image size: 1751517, targets: 1
    b'Target' 0, alt setting: 0, name: "ST...", size: 1751232, elements: 2
      0, address: 0x08000000, size: 15736
      1, address: 0x08020000, size: 1735480
    usb: 0483:df11, device: 0x0000, dfu: 0x011a, b'UFD', 16, 0x61194f1d
Writing memory...
0x08000000   15736 [                         ]   0% Traceback (most recent call last):
  File "src\micropython\tools\pydfu.py", line 548, in <module>
    main()
  File "src\micropython\tools\pydfu.py", line 539, in main
    write_elements(elements, args.mass_erase, progress=cli_progress)
  File "src\micropython\tools\pydfu.py", line 454, in write_elements
    progress(elem_addr, 0, elem_size)
  File "src\micropython\tools\pydfu.py", line 485, in cli_progress
    sys.stdout.flush()
OSError: [WinError 87] The parameter is incorrect

I think it's the same as described in: pytest-dev/py#103

Their workaround appears to be fairly long winded and I'm not sure it's really necessary here (https://github.com/pytest-dev/pytest/pull/2462/files)

I've found it works just fine to catch and ignore the error on the flush line.

Tested:
Windows 10 x64 1803 (Build 17134.228)
Python 3.6.4 amd64

@dpgeorge
Copy link
Member

It looks ok to me.

But did you try sys.stdout.buffer.flush() or sys.stdout.buffer.raw.flush() instead? It's a long shot but might work.

@andrewleech
Copy link
Contributor Author

No, never thought of that. I'd be more wary of either of them not working on other platforms.

I don't think it's particularly buffered on windows anyway, the progress bars seem to work fine anyway.

@dpgeorge
Copy link
Member

Ok, merged in a270364

@dpgeorge dpgeorge closed this Sep 21, 2018
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