find_free_port

Documentation for eth_defi.utils.find_free_port function.

find_free_port(min_port=20000, max_port=40000, max_attempt=20)[source]

Find a free localhost port to bind.

Does by random.

Note

Subject to race condition, but should be rareish.

Parameters
  • min_port (int) – Minimum port range

  • max_port (int) – Maximum port range

  • max_attempt (int) – Give up and die with an exception if no port found after this many attempts.

Returns

Free port number

Return type

int