How does plotly know of ports in use?

Refer to this simple example:

If I call multiple times, plotly seems to know which port to use depending on the ports already in use.

Can I be pointed out to the code segment that checks which ports are already in use and how it determines which one to write on? Any other reference would also be appreciated.

This knowledge is useful to launch plotly app in a multi-user machine, where users can be using the app simultaneously and only one user can write to port 8050 at a time.

Hi all, can I get a response on this?

The open source repository for is here: GitHub - plotly/ The interactive graphing library for Python This project now includes Plotly Express!

I know where the repository is but thanks. I was hoping to get direction towards a β€œcode segment”, not the whole repository. However, I did some digging on my own and found the following lines:

While I am not yet sure if I shall find my answers in the lines but putting them here anyway in case you have anything to say about them.

Hey Mate,

According to the source code you sent, they use this class: http.server β€” HTTP servers β€” Python 3.11.4 documentation so the port number is specified as 0 i.e. it is dynamically allocated.