FT232R: use native Python time.sleep() on Linux #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes compatibility with certain libc implementations, e.g. musl on OpenWrt
When trying to use PyDMX with the FTDI driver on an OpenWrt device,
I found it was not outputting any DMX signal, while the same code was working fine on a ubuntu desktop.
As it turned out, there seems to be an issue with the musl implementation of nanosleep as used by OpenWrt,
which made me wonder about the advantage of calling a ctypes function here, rather than using native Python3 sleep().
Regarding performance of the DMX output, I made a few measurements on both desktop and an mt7621-based OpenWrt router, and it did not make any noticeable difference (actually CPython would use usleep or nanosleep anyways, when available), c.f.: https://forum.openwrt.org/t/python3-ctypes-nanosleep-broken-with-musl/216072/11
Could we just change it to use time.sleep() here?
Besides being more Pythonic, at least it made it work on OpenWrt for me 🙂
besides, the original code seemed wrong regarding the use of modulo to split the fractional part off the nanoseconds:
in wait_ms there is
but in wait_us:
probably should have been
instead? For this driver it would not make any difference of course, since sleep is never called with full seconds.