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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Python application with socket in Pipelines


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
- step:
- pip install --upgrade pip
- pip install --upgrade sockets coverage
- git submodule update --init
- python -m coverage run -m unittest discover
- bash <(curl -s

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/", line 932, in _bootstrap_inner
File "/opt/atlassian/pipelines/agent/build/uart3br/", line 50, in run
self.socket.bind((self.HOST, self.PORT))
OSError: [Errno 98] Address already in use

# ...

The complete pipe (and source):!/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(('', 52184))


# ...


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

OSError: [Errno 98] Address already in use


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

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:!/results/9

So there is nothing keeping sockets from working.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,725 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you