Skip to content

Commit b7056ce

Browse files
committed
Improve Windows compatibility
Add command to Dockerfile to automatically remove any CRLF line termination from the entry point script. They are sometimes added by git when it runs on Windows and they prevent the script from running when the file is copied back on a Linux image. Add code in cmqttd.py that is triggered when the Python code is run directly on Windows. It deals with an issue related to windows ports' behavior within the event loop that results in an error. The issue is documented here: Configuration of windows event loop for libraries python/cpython#81554 It is useful when porting the python code to a Windows system.
1 parent cc0bdf3 commit b7056ce

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎Dockerfile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ RUN pip3 install 'parameterized' && \
2727
# cmqttd runner image
2828
FROM base as cmqttd
2929
COPY COPYING COPYING.LESSER Dockerfile README.md entrypoint-cmqttd.sh /
30+
RUN sed -i 's/\r$//' entrypoint-cmqttd.sh
3031
COPY --from=builder /cbus/dist/cbus-0.2.generic.tar.gz /
3132
RUN tar zxf /cbus-0.2.generic.tar.gz && rm /cbus-0.2.generic.tar.gz
3233

‎cbus/daemon/cmqttd.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
from typing import Any, BinaryIO, Dict, Optional, Text, TextIO
2323

2424
import paho.mqtt.client as mqtt
25+
import sys
26+
27+
if sys.platform == 'win32':
28+
from asyncio import set_event_loop_policy, WindowsSelectorEventLoopPolicy
29+
set_event_loop_policy(WindowsSelectorEventLoopPolicy())
2530

2631
try:
2732
from serial_asyncio import create_serial_connection

0 commit comments

Comments
 (0)