fpgmaas/cookiecutter-poetry

Launch dev server with `use_exec`

Opened this issue · 0 comments

Is your feature request related to a problem? Please describe.

I can't use my debugger (pudb) with poe api --dev because it is launched in the background. It triggers an error when the debugger is supposed to open:

  File "[...]/site-packages/pudb/debugger.py", line 2683, in event_loop
    keys = self.screen.get_input()
  File "[...]/site-packages/urwid/display/_raw_display_base.py", line 286, in get_input
    keys, raw = self.parse_input(None, None, self.get_available_raw_input())

  [...]

  File "[...]/site-packages/urwid/display/_posix_raw_display.py", line 298, in _getch
    return ord(os.read(fd, 1))
TypeError: ord() expected a character, but string of length 0 found

Describe the solution you would like

Launch the dev server with use_exec = true c.f. https://poethepoet.natn.io/tasks/options.html#defining-tasks-that-run-via-exec-instead-of-a-subprocess

For my project I changed the tasks declarations like that:

  [tool.poe.tasks.dev]
  help = "Serve a REST API for DEV purpose"
  use_exec = true
  cmd = """
    uvicorn \ 
      --host $host \
      --port $port \
      --reload \
      --log-level debug \
      network_manager.api:app
    """

    [[tool.poe.tasks.dev.args]]
    help = "Bind socket to this host (default: 0.0.0.0)"
    name = "host"
    options = ["--host"]
    default = "0.0.0.0"

    [[tool.poe.tasks.dev.args]]
    help = "Bind socket to this port (default: 8000)"
    name = "port"
    options = ["--port"]
    default = "8000"

  [tool.poe.tasks.api]
  help = "Serve a REST API"
  use_exec = true
  cmd = """
    gunicorn \
      --access-logfile - \
      --bind $host:$port \
      --graceful-timeout 10 \
      --keep-alive 10 \
      --log-file - \
      --timeout 30 \
      --worker-class uvicorn.workers.UvicornWorker \
      --worker-tmp-dir /dev/shm \
      --workers 2 \
      network_manager.api:app
    """

    [[tool.poe.tasks.api.args]]
    help = "Bind socket to this host (default: 0.0.0.0)"
    name = "host"
    options = ["--host"]
    default = "0.0.0.0"

    [[tool.poe.tasks.api.args]]
    help = "Bind socket to this port (default: 8000)"
    name = "port"
    options = ["--port"]
    default = "8000"
  • remove the dev option and split the existing task in 2
  • use cmd with use_exec instead of shell

Because when using use_exec, it's not possible to use shell. And when using cmd, it's not possible to use the shell if instruction... there might be a better way but this seems to work.

Additional context

There might be a better solution... but I can create a pull request if you are happy with this.