Skip to content

Debugpy unable to start Flask server #1296

Closed

Description

Environment data

  • debugpy version: 1.6.7
  • OS and version: macOS Ventura 13.2.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.10.11
  • Using VS Code or Visual Studio: VS Code
  • Flask version: 2.3.2

Actual behaviour

When using a startup command to run a Flask server with debugpy and code reloading like this:
FLASK_DEBUG=true FLASK_ENV=development python3 -m debugpy --listen 0.0.0.0:5678 -m flask run

debugpy raises a RuntimeException:

Details
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
* Restarting with watchdog (fsevents)
Traceback (most recent call last):
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
  main()
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
  globals = debugger.run(setup['file'], None, None, is_module)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2510, in run
  return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2528, in _exec
  globals = pydevd_runpy._run_module_as_main(module_name, alter_argv=False)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 238, in _run_module_as_main
  return _run_code(code, main_globals, None,
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
  exec(code, run_globals)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/__main__.py", line 39, in <module>
  cli.main()
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 430, in main
  run()
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 302, in run_module
  start_debugging(argv_0)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 256, in start_debugging
  debugpy.listen(options.address)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/public_api.py", line 31, in wrapper
  return wrapped(*args, **kwargs)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/api.py", line 143, in debug
  log.reraise_exception("{0}() failed:", func.__name__, level="info")
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/api.py", line 141, in debug
  return func(address, settrace_kwargs, **kwargs)
File "/home/topeltr/Documents/Github/example-application/venv/lib/python3.10/site-packages/debugpy/server/api.py", line 262, in listen
  raise RuntimeError(str(endpoints["error"]))
RuntimeError: Can't listen for client connections: [Errno 48] Address already in use

I looked a bit more into the problem and it seems that a change in Werkzeug causes this. sys.orig_argv passes the entire command to the reloader i.e. python3 -m debugpy --listen 0.0.0.0:5678 -m flask run - which leads to a second instance of debugpy being started without shutting down the previous one causing the traceback from debugpy side. I already raised an issue on the Werkzeug side and they signalled that it should be handled on the debugpy side.

Expected behaviour

No RuntimeError emitted and Debugpy can start a Flask server with code reloading.

Steps to reproduce:

  1. Use versions mentioned in the environments section
  2. Run minimal Flask app (example here)

Activity

  1. added
    bug
    on Jun 6, 2023
  2. jaredannis commented on Jun 28, 2023

    @jaredannis

    i am having same issue, in my docker compose:

    command: python -m debugpy --listen 0.0.0.0:5666 -m flask run --host=0.0.0.0

    gets error:

    RuntimeError: Can't listen for client connections: [Errno 98] Address already in use

    setting flask to --no-reload lets the app load, but i am losing functionality

    i am able to get it to work if explicitly set these versions:
    werkzeug==2.2.2
    flask==2.2.2
    debugpy==1.6.3

  3. srh-sloan commented on Nov 16, 2023

    @srh-sloan

    We are also experiencing exactly this problem. Is there any update on when it will be fixed please?

  4. sebastienpires commented on Dec 4, 2023

    @sebastienpires

    Same issue here - we start losing the ability to debug if we upgrade any Python3.10 application to Werkzeug 2.3.0.

  5. int19h commented on Dec 4, 2023

    @int19h
    Contributor

    Note that you can disable the Flask reloader by using --no-reload without disabling other Flask debugging features.

  6. yezhengli-Mr9 commented on Jan 1, 2024

    @yezhengli-Mr9

    Are you following https://code.visualstudio.com/docs/containers/docker-compose for python with docker-compose? Not able to debug in vscode same way as pycharm in j2eeexpert2015/flask_docker#1 although feel I need to debug in vscode j2eeexpert2015/springbootdebug#1 due to the fact I need to run docker-compose up under sudo su.

    For https://code.visualstudio.com/docs/containers/docker-compose and utilizing sample code https://github.com/j2eeexpert2015/flask_docker, I finish following steps:

    1. On the Debug tab, choose the Configuration dropdown, choose New Configuration, choose Python, and select the Remote Attach configuration template. Result in following launch.json:
     {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Remote Attach",
                "type": "python",
                "request": "attach",
                "connect": {
                    "host": "localhost",
                    "port": 5678
                },
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "."
                    }
                ],
                "justMyCode": true
            }
        ]
    }
    1. copydocker-compose.yaml https://github.com/j2eeexpert2015/flask_docker/blob/587dc48e1a563226e5fd1ac63e82243590649f5c/docker-compose.yml#L4-L8 as docker-compose.debug.yaml and add into ``docker-compose.debug.yaml` as following
    version: "2"
    services:
      app:
        build: ./app
    ++  command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 app.py runserver 0.0.0.0:5000 --nothreading --noreload"]
        links:
          - db
        ports:
          - "5000:5000"
    ++    - 5678:5678
    
      db:
        image: mysql:5.7
        ports:
          - "32000:3306"
        environment:
          MYSQL_ROOT_PASSWORD: root
        volumes:
          - ./db:/docker-entrypoint-initdb.d/:ro
    1. Add RUN pip install debugpy to DockerFile just in case https://github.com/j2eeexpert2015/flask_docker/blob/587dc48e1a563226e5fd1ac63e82243590649f5c/app/Dockerfile#L10-L11
      COPY app.py /app
    ++RUN pip install debugpy 
      CMD python app.py
    1. Add breakpoint in same as video tutorial
      image

    2. Right-click on the docker-compose.debug.yml file and choose Compose Up:

    Executing task: docker compose -f "docker-compose.debug.yml" up -d --build 
    
    [+] Building 0.6s (11/11) FINISHED                                                                                                                          docker:default
     => [app internal] load .dockerignore                                                                                                                                 0.0s
     => => transferring context: 2B                                                                                                                                       0.0s
     => [app internal] load build definition from Dockerfile                                                                                                              0.0s
     => => transferring dockerfile: 206B                                                                                                                                  0.0s
     => [app internal] load metadata for docker.io/library/python:3.6                                                                                                     0.4s
     => [app 1/6] FROM docker.io/library/python:3.6@sha256:f8652afaf88c25f0d22354d547d892591067aa4026a7fa9a6819df9f300af6fc                                               0.0s
     => [app internal] load build context                                                                                                                                 0.0s
     => => transferring context: 63B                                                                                                                                      0.0s
     => CACHED [app 2/6] WORKDIR /app                                                                                                                                     0.0s
     => CACHED [app 3/6] COPY requirements.txt /app                                                                                                                       0.0s
     => CACHED [app 4/6] RUN pip install -r requirements.txt                                                                                                              0.0s
     => CACHED [app 5/6] COPY app.py /app                                                                                                                                 0.0s
     => CACHED [app 6/6] RUN pip install debugpy                                                                                                                          0.0s
     => [app] exporting to image                                                                                                                                          0.0s
     => => exporting layers                                                                                                                                               0.0s
     => => writing image sha256:6f77b8fe1a24179a7ee1f8450ecf30f33a8a2d01cb8523fbe1891679882967eb                                                                          0.0s
     => => naming to docker.io/library/flask_docker-app                                                                                                                   0.0s
    [+] Running 3/3
     ✔ Network flask_docker_default  Created                                                                                                                              0.1s 
     ✔ Container flask_docker-db-1   Started                                                                                                                              0.1s 
     ✔ Container flask_docker-app-1  Started                                                                                                                              0.1s 
     *  Terminal will be reused by tasks, press any key to close it. 

    or docker-compose up in terminal (similar to Java Debugging in Docker: How to Use VS Code and Docker Compose with sample code https://github.com/j2eeexpert2015/springbootdebug)

    docker-compose up
    Creating network "flask_docker_default" with the default driver
    Creating flask_docker_db_1 ... done
    Creating flask_docker_app_1 ... done
    Attaching to flask_docker_db_1, flask_docker_app_1
    db_1   | 2024-01-01 22:32:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
    db_1   | 2024-01-01 22:32:02+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
    db_1   | 2024-01-01 22:32:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
    db_1   | 2024-01-01 22:32:02+00:00 [Note] [Entrypoint]: Initializing database files
    db_1   | 2024-01-01T22:32:02.961535Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    db_1   | 2024-01-01T22:32:03.211579Z 0 [Warning] InnoDB: New log files created, LSN=45790
    db_1   | 2024-01-01T22:32:03.271596Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    db_1   | 2024-01-01T22:32:03.342051Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9614249d-a8f5-11ee-afd7-0242ac140002.
    db_1   | 2024-01-01T22:32:03.348199Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    db_1   | 2024-01-01T22:32:03.465054Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:03.465064Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:03.465341Z 0 [Warning] CA certificate ca.pem is self signed.
    db_1   | 2024-01-01T22:32:03.471705Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    app_1  | Collecting debugpy
    app_1  |   Using cached debugpy-1.5.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.9 MB)
    app_1  | Installing collected packages: debugpy
    app_1  | Successfully installed debugpy-1.5.1
    app_1  | WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
    app_1  | WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
    app_1  | You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
    db_1   | 2024-01-01 22:32:07+00:00 [Note] [Entrypoint]: Database files initialized
    db_1   | 2024-01-01 22:32:07+00:00 [Note] [Entrypoint]: Starting temporary server
    db_1   | 2024-01-01 22:32:08+00:00 [Note] [Entrypoint]: Waiting for server startup
    db_1   | 2024-01-01T22:32:08.159998Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    db_1   | 2024-01-01T22:32:08.160922Z 0 [Note] mysqld (mysqld 5.7.44) starting as process 124 ...
    db_1   | 2024-01-01T22:32:08.162816Z 0 [Note] InnoDB: PUNCH HOLE support available
    db_1   | 2024-01-01T22:32:08.162833Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    db_1   | 2024-01-01T22:32:08.162835Z 0 [Note] InnoDB: Uses event mutexes
    db_1   | 2024-01-01T22:32:08.162838Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    db_1   | 2024-01-01T22:32:08.162839Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
    db_1   | 2024-01-01T22:32:08.162840Z 0 [Note] InnoDB: Using Linux native AIO
    db_1   | 2024-01-01T22:32:08.163000Z 0 [Note] InnoDB: Number of pools: 1
    db_1   | 2024-01-01T22:32:08.163069Z 0 [Note] InnoDB: Using CPU crc32 instructions
    db_1   | 2024-01-01T22:32:08.164143Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
    db_1   | 2024-01-01T22:32:08.167973Z 0 [Note] InnoDB: Completed initialization of buffer pool
    db_1   | 2024-01-01T22:32:08.169052Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
    db_1   | 2024-01-01T22:32:08.180233Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
    db_1   | 2024-01-01T22:32:08.197763Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
    db_1   | 2024-01-01T22:32:08.197808Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
    db_1   | 2024-01-01T22:32:08.213086Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
    db_1   | 2024-01-01T22:32:08.213443Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
    db_1   | 2024-01-01T22:32:08.213447Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
    db_1   | 2024-01-01T22:32:08.213703Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 2768291
    db_1   | 2024-01-01T22:32:08.213814Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
    db_1   | 2024-01-01T22:32:08.213934Z 0 [Note] Plugin 'FEDERATED' is disabled.
    db_1   | 2024-01-01T22:32:08.214805Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240101 22:32:08
    db_1   | 2024-01-01T22:32:08.217155Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
    db_1   | 2024-01-01T22:32:08.217161Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
    db_1   | 2024-01-01T22:32:08.217163Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:08.217164Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:08.217463Z 0 [Warning] CA certificate ca.pem is self signed.
    db_1   | 2024-01-01T22:32:08.217481Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
    db_1   | 2024-01-01T22:32:08.223329Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
    db_1   | 2024-01-01T22:32:08.226573Z 0 [Note] Event Scheduler: Loaded 0 events
    db_1   | 2024-01-01T22:32:08.226696Z 0 [Note] mysqld: ready for connections.
    db_1   | Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
    db_1   | 2024-01-01 22:32:09+00:00 [Note] [Entrypoint]: Temporary server started.
    db_1   | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
    db_1   | 2024-01-01T22:32:09.026098Z 3 [Note] InnoDB: Stopping purge
    db_1   | 2024-01-01T22:32:09.046927Z 3 [Note] InnoDB: Resuming purge
    db_1   | 2024-01-01T22:32:09.052902Z 3 [Note] InnoDB: Stopping purge
    db_1   | 2024-01-01T22:32:09.064590Z 3 [Note] InnoDB: Resuming purge
    db_1   | 2024-01-01T22:32:09.070887Z 3 [Note] InnoDB: Stopping purge
    db_1   | 2024-01-01T22:32:09.082701Z 3 [Note] InnoDB: Resuming purge
    db_1   | 2024-01-01T22:32:09.089075Z 3 [Note] InnoDB: Stopping purge
    db_1   | 2024-01-01T22:32:09.101439Z 3 [Note] InnoDB: Resuming purge
    db_1   | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
    db_1   | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
    db_1   | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
    db_1   | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
    db_1   | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
    db_1   | 
    db_1   | 2024-01-01 22:32:10+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
    db_1   | 
    db_1   | 
    db_1   | 2024-01-01 22:32:10+00:00 [Note] [Entrypoint]: Stopping temporary server
    db_1   | 2024-01-01T22:32:10.153423Z 0 [Note] Giving 0 client threads a chance to die gracefully
    db_1   | 2024-01-01T22:32:10.153437Z 0 [Note] Shutting down slave threads
    db_1   | 2024-01-01T22:32:10.153440Z 0 [Note] Forcefully disconnecting 0 remaining clients
    db_1   | 2024-01-01T22:32:10.153443Z 0 [Note] Event Scheduler: Purging the queue. 0 events
    db_1   | 2024-01-01T22:32:10.153465Z 0 [Note] Binlog end
    db_1   | 2024-01-01T22:32:10.160297Z 0 [Note] Shutting down plugin 'ngram'
    db_1   | 2024-01-01T22:32:10.160311Z 0 [Note] Shutting down plugin 'partition'
    db_1   | 2024-01-01T22:32:10.160313Z 0 [Note] Shutting down plugin 'BLACKHOLE'
    db_1   | 2024-01-01T22:32:10.160315Z 0 [Note] Shutting down plugin 'ARCHIVE'
    db_1   | 2024-01-01T22:32:10.160317Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
    db_1   | 2024-01-01T22:32:10.160338Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
    db_1   | 2024-01-01T22:32:10.160340Z 0 [Note] Shutting down plugin 'MyISAM'
    db_1   | 2024-01-01T22:32:10.160351Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
    db_1   | 2024-01-01T22:32:10.160353Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
    db_1   | 2024-01-01T22:32:10.160355Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
    db_1   | 2024-01-01T22:32:10.160356Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
    db_1   | 2024-01-01T22:32:10.160357Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
    db_1   | 2024-01-01T22:32:10.160358Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
    db_1   | 2024-01-01T22:32:10.160360Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
    db_1   | 2024-01-01T22:32:10.160361Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
    db_1   | 2024-01-01T22:32:10.160361Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
    db_1   | 2024-01-01T22:32:10.160362Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
    db_1   | 2024-01-01T22:32:10.160364Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
    db_1   | 2024-01-01T22:32:10.160364Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
    db_1   | 2024-01-01T22:32:10.160365Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
    db_1   | 2024-01-01T22:32:10.160366Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
    db_1   | 2024-01-01T22:32:10.160367Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
    db_1   | 2024-01-01T22:32:10.160368Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
    db_1   | 2024-01-01T22:32:10.160369Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
    db_1   | 2024-01-01T22:32:10.160370Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
    db_1   | 2024-01-01T22:32:10.160371Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
    db_1   | 2024-01-01T22:32:10.160372Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
    db_1   | 2024-01-01T22:32:10.160373Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
    db_1   | 2024-01-01T22:32:10.160374Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
    db_1   | 2024-01-01T22:32:10.160376Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
    db_1   | 2024-01-01T22:32:10.160377Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
    db_1   | 2024-01-01T22:32:10.160378Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
    db_1   | 2024-01-01T22:32:10.160379Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
    db_1   | 2024-01-01T22:32:10.160380Z 0 [Note] Shutting down plugin 'INNODB_CMP'
    db_1   | 2024-01-01T22:32:10.160381Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
    db_1   | 2024-01-01T22:32:10.160382Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
    db_1   | 2024-01-01T22:32:10.160383Z 0 [Note] Shutting down plugin 'INNODB_TRX'
    db_1   | 2024-01-01T22:32:10.160384Z 0 [Note] Shutting down plugin 'InnoDB'
    db_1   | 2024-01-01T22:32:10.160442Z 0 [Note] InnoDB: FTS optimize thread exiting.
    db_1   | 2024-01-01T22:32:10.160555Z 0 [Note] InnoDB: Starting shutdown...
    db_1   | 2024-01-01T22:32:10.260733Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
    db_1   | 2024-01-01T22:32:10.260877Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 240101 22:32:10
    db_1   | 2024-01-01T22:32:11.290973Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12227086
    db_1   | 2024-01-01T22:32:11.292015Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
    db_1   | 2024-01-01T22:32:11.292035Z 0 [Note] Shutting down plugin 'MEMORY'
    db_1   | 2024-01-01T22:32:11.292038Z 0 [Note] Shutting down plugin 'CSV'
    db_1   | 2024-01-01T22:32:11.292040Z 0 [Note] Shutting down plugin 'sha256_password'
    db_1   | 2024-01-01T22:32:11.292040Z 0 [Note] Shutting down plugin 'mysql_native_password'
    db_1   | 2024-01-01T22:32:11.292114Z 0 [Note] Shutting down plugin 'binlog'
    db_1   | 2024-01-01T22:32:11.293093Z 0 [Note] mysqld: Shutdown complete
    db_1   | 
    db_1   | 2024-01-01 22:32:12+00:00 [Note] [Entrypoint]: Temporary server stopped
    db_1   | 
    db_1   | 2024-01-01 22:32:12+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
    db_1   | 
    db_1   | 2024-01-01T22:32:12.320317Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    db_1   | 2024-01-01T22:32:12.324342Z 0 [Note] mysqld (mysqld 5.7.44) starting as process 1 ...
    db_1   | 2024-01-01T22:32:12.327188Z 0 [Note] InnoDB: PUNCH HOLE support available
    db_1   | 2024-01-01T22:32:12.327210Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    db_1   | 2024-01-01T22:32:12.327214Z 0 [Note] InnoDB: Uses event mutexes
    db_1   | 2024-01-01T22:32:12.327216Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    db_1   | 2024-01-01T22:32:12.327220Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
    db_1   | 2024-01-01T22:32:12.327221Z 0 [Note] InnoDB: Using Linux native AIO
    db_1   | 2024-01-01T22:32:12.327466Z 0 [Note] InnoDB: Number of pools: 1
    db_1   | 2024-01-01T22:32:12.327563Z 0 [Note] InnoDB: Using CPU crc32 instructions
    db_1   | 2024-01-01T22:32:12.328833Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
    db_1   | 2024-01-01T22:32:12.343717Z 0 [Note] InnoDB: Completed initialization of buffer pool
    db_1   | 2024-01-01T22:32:12.345509Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
    db_1   | 2024-01-01T22:32:12.365297Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
    db_1   | 2024-01-01T22:32:12.384479Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
    db_1   | 2024-01-01T22:32:12.384535Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
    db_1   | 2024-01-01T22:32:12.403458Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
    db_1   | 2024-01-01T22:32:12.404061Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
    db_1   | 2024-01-01T22:32:12.404070Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
    db_1   | 2024-01-01T22:32:12.404452Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 12227086
    db_1   | 2024-01-01T22:32:12.404571Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
    db_1   | 2024-01-01T22:32:12.404810Z 0 [Note] Plugin 'FEDERATED' is disabled.
    db_1   | 2024-01-01T22:32:12.407917Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240101 22:32:12
    db_1   | 2024-01-01T22:32:12.409841Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
    db_1   | 2024-01-01T22:32:12.409855Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
    db_1   | 2024-01-01T22:32:12.409858Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:12.409859Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
    db_1   | 2024-01-01T22:32:12.410374Z 0 [Warning] CA certificate ca.pem is self signed.
    db_1   | 2024-01-01T22:32:12.410410Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
    db_1   | 2024-01-01T22:32:12.410708Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
    db_1   | 2024-01-01T22:32:12.410743Z 0 [Note] IPv6 is available.
    db_1   | 2024-01-01T22:32:12.410754Z 0 [Note]   - '::' resolves to '::';
    db_1   | 2024-01-01T22:32:12.410772Z 0 [Note] Server socket created on IP: '::'.
    db_1   | 2024-01-01T22:32:12.416621Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
    db_1   | 2024-01-01T22:32:12.421924Z 0 [Note] Event Scheduler: Loaded 0 events
    db_1   | 2024-01-01T22:32:12.422097Z 0 [Note] mysqld: ready for connections.
    db_1   | Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
    1. hit F5 with the Python: Remote Attach launch configuration selected.
    2. Open browser and go to localhost:5000

    While localhost:5000 in the browser smoothly returns

    {"get_employees": [{"Employee1": "Developer"}, {"Employee2": "HR"}]}`

    the breakpoint turns from red to hollow circle and never get hit
    image

  7. yezhengli-Mr9 commented on Jan 1, 2024

    @yezhengli-Mr9

    Submit issue #1491

  8. stevefoga commented on Feb 13, 2024

    @stevefoga

    Did anybody ever find a workaround for this?

  9. Keith-CPlus commented on Feb 23, 2024

    @Keith-CPlus

    Any other workaround for this? Other than bumping down werkzeug and flask versions?

  10. lukaspiatkowski commented on Mar 21, 2024

    @lukaspiatkowski

    I've got a workaround, but you have to use debugpy API instead of the CLI. Just find the place in your code before you call run(... , use_reloader=True) on your flask app and add:

    if (
        # The WERKZEUG_RUN_MAIN is set to true when running the subprocess for
        # reloading, we want to start debugpy only once during the first
        # invocation and never during reloads.
        os.environ.get("WERKZEUG_RUN_MAIN") != "true"
    ):
        import debugpy
    
        debugpy.listen(("0.0.0.0", 5678))
        debugpy.wait_for_client()
    

    This will start debugpy only for the first original invocation of your app and not for the subsequent reload invocations. The WERKZEUG_RUN_MAIN env variable is set by Werkezeug itself and is used to identify if this is the reloadable subprocess.

  11. Keith-CPlus commented on Mar 26, 2024

    @Keith-CPlus

    I've got a workaround, but you have to use debugpy API instead of the CLI. Just find the place in your code before you call run(... , use_reloader=True) on your flask app and add:

    if (
        # The WERKZEUG_RUN_MAIN is set to true when running the subprocess for
        # reloading, we want to start debugpy only once during the first
        # invocation and never during reloads.
        os.environ.get("WERKZEUG_RUN_MAIN") != "true"
    ):
        import debugpy
    
        debugpy.listen(("0.0.0.0", 5678))
        debugpy.wait_for_client()
    

    This will start debugpy only for the first original invocation of your app and not for the subsequent reload invocations. The WERKZEUG_RUN_MAIN env variable is set by Werkezeug itself and is used to identify if this is the reloadable subprocess.

    This workaround works, but I seemed to be getting SystemExit: 3, although it doesn't affect functionality.
    Screenshot 2024-03-26 at 11 45 10 AM

  12. davidlougheed commented on Apr 15, 2024

    @davidlougheed

    still encountering this; I need to keep live reloading enabled in a dev image with debugpy installed, and for now I'm stuck on Flask 2.2 until this gets fixed.

  13. MaximeOlivie commented on Apr 29, 2024

    @MaximeOlivie

    Same here. Very annoying. No new workaround from someone?

  14. madolmo commented on May 5, 2024

    @madolmo

    Same problem. Just upgrading from Werkzeug 2.2.2 to 2.3.8 debugpy doesen't work anymore.

  15. sevenearths commented on May 14, 2024

    @sevenearths

    Same here. I have a project waiting for this update :(

  16. oelhammouchi commented on Aug 26, 2024

    @oelhammouchi
    Contributor

    I've tried to provide a fix in #1657 since I need this functionality for a dockerised Flask project. So far it seems to work just fine. The tests are also positive with the exception of test_attach_pid_client. I'm using Debian and according to #311 it should be working on Linux, but it doesn't for me. I get the same test errors on the original code though so it's not due to the change.

  17. rchiodo commented on Aug 27, 2024

    @rchiodo
    Contributor

    This seems to work for me with the latest bits of debugpy and werkzeug. I do get an exception when reloading, but debugpy does attach to the new instance:

     * Detected change in 'C:\\Users\\rchiodo\\source\\testing\\flask_tutorial\\hello.py', reloading
    Exception in thread Thread-6 (serve_forever):
    Traceback (most recent call last):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 1045, in _bootstrap_inner
        self.run()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 982, in run
        self._target(*self._args, **self._kwargs)
      File "c:\Users\rchiodo\source\testing\flask_tutorial\.venv\Lib\site-packages\werkzeug\serving.py", line 817, in serve_forever
        super().serve_forever(poll_interval=poll_interval)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\socketserver.py", line 233, in serve_forever
        ready = selector.select(poll_interval)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\selectors.py", line 323, in select
        r, w, _ = self._select(self._readers, self._writers, [], timeout)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\selectors.py", line 314, in _select
        r, w, x = select.select(r, w, w, timeout)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    OSError: [WinError 10038] An operation was attempted on something that is not a socket
     * Restarting with stat
    127.0.0.1 - - [27/Aug/2024 10:53:21] "GET / HTTP/1.1" 200 -
    

    I have werkzeug 3.0.4 and debugpy 1.8.5

  18. oelhammouchi commented on Aug 27, 2024

    @oelhammouchi
    Contributor

    This seems to work for me with the latest bits of debugpy and werkzeug. I do get an exception when reloading, but debugpy does attach to the new instance:

     * Detected change in 'C:\\Users\\rchiodo\\source\\testing\\flask_tutorial\\hello.py', reloading
    Exception in thread Thread-6 (serve_forever):
    Traceback (most recent call last):
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 1045, in _bootstrap_inner
        self.run()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\threading.py", line 982, in run
        self._target(*self._args, **self._kwargs)
      File "c:\Users\rchiodo\source\testing\flask_tutorial\.venv\Lib\site-packages\werkzeug\serving.py", line 817, in serve_forever
        super().serve_forever(poll_interval=poll_interval)
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\socketserver.py", line 233, in serve_forever
        ready = selector.select(poll_interval)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\selectors.py", line 323, in select
        r, w, _ = self._select(self._readers, self._writers, [], timeout)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.2544.0_x64__qbz5n2kfra8p0\Lib\selectors.py", line 314, in _select
        r, w, x = select.select(r, w, w, timeout)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    OSError: [WinError 10038] An operation was attempted on something that is not a socket
     * Restarting with stat
    127.0.0.1 - - [27/Aug/2024 10:53:21] "GET / HTTP/1.1" 200 -
    

    I have werkzeug 3.0.4 and debugpy 1.8.5

    On Debian, I get this fatal error:

    Traceback (most recent call last):
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 3489, in <module>
        main()
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 3482, in main
        globals = debugger.run(setup['file'], None, None, is_module)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2510, in run
        return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/pydevd.py", line 2528, in _exec
        globals = pydevd_runpy._run_module_as_main(module_name, alter_argv=False)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 238, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
        exec(code, run_globals)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/__main__.py", line 71, in <module>
        cli.main()
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 486, in main
        run()
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 354, in run_module
        start_debugging(argv_0)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/cli.py", line 308, in start_debugging
        debugpy.listen(options.address)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/public_api.py", line 31, in wrapper
        return wrapped(*args, **kwargs)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/api.py", line 143, in debug
        log.reraise_exception("{0}() failed:", func.__name__, level="info")
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/api.py", line 141, in debug
        return func(address, settrace_kwargs, **kwargs)
      File "/home/othman/repos/debugpy/.venv/lib/python3.10/site-packages/debugpy/server/api.py", line 262, in listen
        raise RuntimeError(str(endpoints["error"]))
    RuntimeError: Can't listen for client connections: [Errno 98] Address already in use
    

    Same version of werkzeug and debugpy.

  19. rchiodo commented on Aug 27, 2024

    @rchiodo
    Contributor

    Okay must be a linux only issue. I'll try on WSL (don't have a linux machine handy).

  20. rchiodo commented on Aug 27, 2024

    @rchiodo
    Contributor

    Hmm, works fine on WSL too. I don't even get the error I had on windows.

  21. rchiodo commented on Aug 27, 2024

    @rchiodo
    Contributor

    I tried the fix in #1657 and although I can't seem to reproduce the original error, the fix doesn't seem to break anything, so I merged it. Hopefully this fixes the problem for everybody.

  22. int19h commented on Aug 28, 2024

    @int19h
    Contributor

    There's a lot of platform-specific weirdness around sockets, so it's not surprising that behavior differs. Note though that even when it works, it means that you have two different debugpy adapter processes, one of which is trying to manage both the parent and the child, while the other one (the one that causes the error on Linux and quietly overwrites the socket on Windows) is only managing the child. I'm not quite sure what the overall effects of that would be, but it's likely to break eventually.

  23. sebastienpires commented on Aug 28, 2024

    @sebastienpires

    I can confirm that the #1657 fix has resolved the issue I was facing on multiple applications running Python 3.11.

    I've pulled the commit into my requirements file and upgraded Flask to 3.0.3 and Werkzeug to 3.0.4.

    The debugger now starts without any issue and I'm able to use hot-reloading.

    Thanks Othman El Hammouchi (@oelhammouchi) and Rich Chiodo (@rchiodo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions