()
| 400 | def find_available_port(start_port=5000, max_port=6000): |
| 401 | current_port = start_port |
| 402 | while (current_port <= max_port): |
| 403 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 404 | try: |
| 405 | sock.bind(('', current_port)) |
| 406 | sock.close() |
| 407 | return current_port |
| 408 | except OSError: |
| 409 | current_port += 1 |
| 410 | finally: |
| 411 | sock.close() |
| 412 | return None |
| 413 | |
| 414 | if __name__ == '__main__': |
| 415 | port = find_available_port() |
| 416 | if port is None: |
| 417 | print("Error: No available ports found between 5000 and 6000") |
| 418 | else: |
| 419 | def open_browser(): |
| 420 | time.sleep(1.5) |
| 421 | webbrowser.open_new(f'http://127.0.0.1:{port}') |
| 422 | |
| 423 | threading.Thread(target=open_browser).start() |
| 424 | |
| 425 | print(f"Starting server on port {port}") |
| 426 | app.run(debug=True, port=port, use_reloader=False, threaded=True) |
nothing calls this directly
no test coverage detected