Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Python application with socket in Pipelines

Roberto-R December 15, 2020

I am developing an application that uses the `sockets` package. I included `unittest` unit tests to test the application.

The complete bitbucket-pipelines.yml:

image: python:3.8
pipelines:
default:
- step:
script:
- pip install --upgrade pip
- pip install --upgrade sockets coverage
- git submodule update --init
- python -m coverage run -m unittest discover
- bash <(curl -s https://codecov.io/bash)

However, the pipeline throws errors when the unit tests are being performed:

+ python -m coverage run -m unittest discover
..........................EException in thread Serial server thread:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/opt/atlassian/pipelines/agent/build/uart3br/_serial_server.py", line 50, in run
self.socket.bind((self.HOST, self.PORT))
OSError: [Errno 98] Address already in use

# ...

The complete pipe (and source): https://bitbucket.org/ctw-bw/micropython-dummy-modules/addon/pipelines/home#!/results/6

Of course the tests pass without problems on my computer (Windows 10, Python 3.8).

The socket creation looks like:

self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Set option to allow instant socket reuse after shutdown
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

self.socket.bind(('127.0.0.1', 52184))

self.socket.listen()

# ...

 

The error trace is a little hard to follow, but two different errors are being throws:

OSError: [Errno 98] Address already in use

and

ConnectionRefusedError: [Errno 111] Connection refused

 

I was wondering if other people have had experience with this and what could be the solution to this problem.

1 answer

1 accepted

0 votes
Answer accepted
Roberto-R December 15, 2020

Figured it out.

I tested the pipeline locally with Docker, where I ran into the same errors. Apparently there is something with the Python image / Debian / Docker (or a combination) that does not allow rapid opening and closing of sockets.

Instead I restructured my tests to only open and close the server socket once (using `setUpClass()` instead of `setUp()`).

Working pipeline: https://bitbucket.org/ctw-bw/micropython-dummy-modules/addon/pipelines/home#!/results/9

So there is nothing keeping sockets from working.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events