Skip to content

chart.py spawns child process chart.py #2

@MatthAlex

Description

@MatthAlex

Seems like debug=True spawns an identical child process for chart.py. This doubles logs and other objects.

Disabling the if __name__ block avoided creating the child-child process.

Running app.run(debug=False) correctly spawns one thread, but also crashes on exit.

$ pstree -p | grep python
           |-tilix(253042)-+-bash(489093)---python3(1299600)-+-QtWebEngineProc(1299640)
           |               |                                 |-python3(1299672)-+-python3(1299730)-+-{python3}(1299731)
           |               |                                 |                  |                  |-{python3}(1299732)
           |               |                                 |                  |                  |-{python3}(1299733)
           |               |                                 |                  |                  |-{python3}(1299734)
           |               |                                 |                  |                  |-{python3}(1299735)
           |               |                                 |                  |                  |-{python3}(1299736)
           |               |                                 |                  |                  |-{python3}(1299737)
           |               |                                 |                  |                  `-{python3}(1299738)
           |               |                                 |                  |-{python3}(1299714)
           |               |                                 |                  |-{python3}(1299715)
           |               |                                 |                  |-{python3}(1299716)
           |               |                                 |                  |-{python3}(1299717)
           |               |                                 |                  |-{python3}(1299718)
           |               |                                 |                  |-{python3}(1299719)
           |               |                                 |                  `-{python3}(1299720)
           |               |                                 |-{python3}(1299608)
           |               |                                 |-{python3}(1299609)

Logs:

2023-08-29 14:48:33,041 - Breksta - INFO - ==================================================
2023-08-29 14:48:33,041 - Breksta - INFO - APP SPOOLING UP!
2023-08-29 14:48:33,074 - Breksta - DEBUG - Default values: Sampling frequency: 2s, Experiment duration: 1h
2023-08-29 14:48:33,075 - Breksta - DEBUG - Sent resume signal to chart control file...
2023-08-29 14:48:33,367 - Breksta - DEBUG - chart.py is called, PID is 1299600
2023-08-29 14:48:33,368 - Breksta - INFO - Starting web process...
2023-08-29 14:48:33,956 - Breksta - DEBUG - Count: 1299672
2023-08-29 14:48:33,956 - Breksta - DEBUG - Parent process ID: 1299600
2023-08-29 14:48:34,462 - Breksta - DEBUG - Count: 1299730
2023-08-29 14:48:34,462 - Breksta - DEBUG - Parent process ID: 1299672
2023-08-29 14:54:25,057 - Breksta - DEBUG - Count: 1300443
2023-08-29 14:54:25,057 - Breksta - DEBUG - Parent process ID: 1299672
2023-08-29 14:54:25,067 - Breksta - DEBUG - THIS SHOULD NEVER APPEAR DURING APP
2023-08-29 14:54:30,984 - Breksta - INFO - APP WINDING DOWN!
2023-08-29 14:54:30,984 - Breksta - INFO - ==================================================

code:

chart.py:
...
logger = setup_logger()
logger.debug("Logger handlers: %s", logger.handlers)
pid = os.getpid()
logger.debug("Count: %s", pid)
logger.debug("Parent process ID: %s", os.getppid())
...
if __name__ == '__main__':
    # Entry point for the script.
    # Starts the Dash server with debugging enabled if the script is run directly.
    # Autoupdate is True by default.
    logger.debug("THIS SHOULD NEVER APPEAR DURING APP")
    app.run_server(debug=True, threaded=True, dev_tools_hot_reload=False)
$ ps -e -o pid,ppid,cmd | grep python
    929       1 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
   1314       1 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
   2324    2191 /usr/bin/python3 /usr/lib/budgie-desktop/plugins/budgie-dropby/dropover a92e3179-0824-11ed-8a51-2911653d9229
1239554 1239464 /usr/share/code/code --ms-enable-electron-run-as-node /home/matt/.vscode/extensions/ms-python.vscode-pylance-2023.8.40/dist/server.bundle.js --cancellationReceive=file:2304c672208cf6106e8850b112bec5ea4e1a3b34f7 --node-ipc --clientProcessId=1239464
1296275  489093 python3 -m app.breksta
1296319 1296275 /home/matt/Documents/git/breksta/env/lib/python3.10/site-packages/PySide6/Qt/libexec/QtWebEngineProcess --type=zygote --no-zygote-sandbox --application-name=breksta.py --webengine-schemes=qrc:sV --lang=en
1296320 1296275 /home/matt/Documents/git/breksta/env/lib/python3.10/site-packages/PySide6/Qt/libexec/QtWebEngineProcess --type=zygote --application-name=breksta.py --webengine-schemes=qrc:sV --lang=en
1296322 1296320 /home/matt/Documents/git/breksta/env/lib/python3.10/site-packages/PySide6/Qt/libexec/QtWebEngineProcess --type=zygote --application-name=breksta.py --webengine-schemes=qrc:sV --lang=en
1296349 1296322 /home/matt/Documents/git/breksta/env/lib/python3.10/site-packages/PySide6/Qt/libexec/QtWebEngineProcess --type=renderer --webengine-schemes=qrc:sV --first-renderer-process --disable-speech-api --enable-threaded-compositing --disable-databases --lang=en --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=3 --time-ticks-at-unix-epoch=-1692411585597707 --launch-time-ticks=904198081505 --shared-files --enable-features=NetworkServiceInProcess2,TracingServiceInProcess --disable-features=BackgroundFetch,ConsolidatedMovementXY,InstalledApp,PictureInPicture,WebOTP,WebPayments,WebUSB
1296355 1296275 /home/matt/Documents/git/breksta/env/bin/python3 -m app.chart
1296363 1296322 /home/matt/Documents/git/breksta/env/lib/python3.10/site-packages/PySide6/Qt/libexec/QtWebEngineProcess --type=renderer --webengine-schemes=qrc:sV --disable-speech-api --enable-threaded-compositing --disable-databases --lang=en --num-raster-threads=4 --enable-main-frame-before-activation --renderer-client-id=4 --time-ticks-at-unix-epoch=-1692411585597707 --launch-time-ticks=904198097157 --shared-files --enable-features=NetworkServiceInProcess2,TracingServiceInProcess --disable-features=BackgroundFetch,ConsolidatedMovementXY,InstalledApp,PictureInPicture,WebOTP,WebPayments,WebUSB
1296430 1296355 /home/matt/Documents/git/breksta/env/bin/python3 -m app.chart
1296602 1296384 grep --color=auto python

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions