Skip to content

python -m src.app.api fails to run #103

@leplatrem

Description

@leplatrem

Since src.app.api has a main, we should be able to run the app locally...

$ JIRA_USERNAME=foo JIRA_API_KEY=bar BUGZILLA_API_KEY=bz PORT=8000 poetry run python -m src.app.api

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/[email protected]/3.9.13_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/mathieu/Code/Mozilla/jira-bugzilla-integration/src/app/api.py", line 143, in <module>
    uvicorn.run(
  File "/Users/mathieu/Library/Caches/pypoetry/virtualenvs/jira-bugzilla-integration-fgdRkTUv-py3.9/lib/python3.9/site-packages/uvicorn/main.py", line 457, in run
    sock = config.bind_socket()
  File "/Users/mathieu/Library/Caches/pypoetry/virtualenvs/jira-bugzilla-integration-fgdRkTUv-py3.9/lib/python3.9/site-packages/uvicorn/config.py", line 551, in bind_socket
    sock.bind((self.host, self.port))
TypeError: an integer is required (got type str)

It looks like environment.py does not have the right types.

I also tried to run the app locally through Gunicorn.

$ poetry run gunicorn -k uvicorn.workers.UvicornWorker -c bin/gunicorn_conf.py src.app.api:app
...
  File "/Users/mathieu/Library/Caches/pypoetry/virtualenvs/jira-bugzilla-integration-fgdRkTUv-py3.9/lib/python3.9/site-packages/gunicorn/workers/workertmp.py", line 22, in __init__
    raise RuntimeError("%s doesn't exist. Can't create workertmp." % fdir)
RuntimeError: /dev/shm doesn't exist. Can't create workertmp.

After a quick fix in gunicorn_conf.py to remove the hard-coded value, I could get Gunicorn to work locally:

$ JIRA_USERNAME=foo JIRA_API_KEY=bar BUGZILLA_API_KEY=bz WORKER_TMP_DIR=/tmp/ poetry run gunicorn -k uvicorn.workers.UvicornWorker -c bin/gunicorn_conf.py src.app.api:app
..
[2022-07-13 15:42:12 +0200] [28107] [INFO] Starting gunicorn 20.1.0
[2022-07-13 15:42:12 +0200] [28107] [INFO] Listening at: http://0.0.0.0:8000 (28107)
[2022-07-13 15:42:12 +0200] [28107] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2022-07-13 15:42:12 +0200] [28109] [INFO] Booting worker with pid: 28109
[2022-07-13 15:42:12 +0200] [28110] [INFO] Booting worker with pid: 28110
...

So, should we keep if __name__ == "__main__" block in src/app/api.py and its related settings in src/environment.py?

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