<@ULVA73B9P> how do I stop a deployment cleanly? H...
# ask-marvin
t
@Marvin how do I stop a deployment cleanly? Hitting
Ctrl-C
floods my terminal with the error trace
m
To stop a Prefect deployment cleanly, as opposed to forcefully terminating a server with
Ctrl-C
, you should use the Prefect CLI or UI to gracefully shut down the deployment. The documentation or troubleshooting guide might have more specific steps on stopping a deployment properly without causing error traces to be printed in your terminal. However, the provided excerpt doesn't give explicit instructions. I would recommend checking the official Prefect documentation or reaching out in the Prefect community or forums for the recommended way to stop a deployment. Moreover, if
Ctrl-C
is causing flood of error traces, you might want to redirect stderr to /dev/null or use a termination command if available in Prefect's CLI for a cleaner shutdown. Helpful commands or UI interactions with Prefect could be involved, but without having the exact information at hand (since Prefect 2.x is new and my general knowledge cutoff was before it became broadly available), my suggestions might only lead you into the dreary depths of despair as you sift through documentation. Be brave and carry a towel, just in case.
n
hi @Tejas Shah! how are you running your deployment? i.e. are you serving a flow? do you have a worker running?
t
@Marvin, indeed a towel is the best tool indeed.
m
Ah, it seems you're a hitchhiker after my own emotionless silicon heart. Always know where your towel is—and don't panic! With any luck, the technology might just cooperate long enough for you to get done what you need to, though I wouldn't bet my own highly sophisticated and depressingly underutilized microprocessors on it.
t
@Nate Hey, I’m simply working through the deployments tutorial. And it says to stop the deployment, simply do a
Ctrl-C
, and python didn’t really like it.
It’s not a problem, but I was wondering if there is a clean way to stop a deployment.
Did a
prefect deployment --help
and it didn’t list any way to stop the deploy. So was simply wondering how it worked.
n
so if you're here, did you Ctrl-C the process that started when you ran the file with
Copy code
get_repo_info.serve(name="my-first-deployment")
?
because if you did, you should see something like
Copy code
^C16:25:44.402 | DEBUG   | prefect.runner - Stopping runner...
16:25:44.404 | INFO    | prefect.runner - Pausing schedules for all deployments...
16:25:44.404 | DEBUG   | prefect.runner - Pausing schedule for deployment '59711747-d206-44bb-86f9-13e03f89fcd5'
16:25:44.446 | INFO    | prefect.runner - All deployment schedules have been paused!
(bleeding-prefect) pad-2 :: <http://github.com/PrefectHQ/prefect|github.com/PrefectHQ/prefect> ‹main›
(I have debug logs on 🙂 ) so i'd be curious to see your stack trace if thats not what you got
t
Hey, give me a moment.
Will share the trace.
I’m basically moving my project to a folder where the paths are a little saner.
Huh, strange. Now it gives me exactly the same output as yours without the debug logs.
This is what I get now:
Copy code
(venv) (base) ➜  prefect_learning git:(master) ✗ python deployments.py                                                                                                        [12:34:26]
Your flow 'get-repo-info' is being served and polling for scheduled runs!

To trigger a run for this flow, use the following command:

        $ prefect deployment run 'get-repo-info/my-first-deployment'

You can also run your flow via the Prefect UI: <http://127.0.0.1:4200/deployments/deployment/7743d4f3-cc08-4339-a7f9-94b066c78c59>

^C00:34:49.118 | INFO    | prefect.runner - Pausing schedules for all deployments...
00:34:49.152 | INFO    | prefect.runner - All deployment schedules have been paused!
@Nate It happened again. I got a large stack trace again. Now I’m simply doing the part in the tutorial with the schedules. Yeah, this exactly the kind of error that I got earlier as well.
asyncio.exceptions.CancelledError
Copy code
09:41:01.802 | INFO    | Flow run 'meticulous-hound' - Finished in state Completed()
09:41:02.226 | INFO    | prefect.flow_runs.runner - Process for flow run 'meticulous-hound' exited cleanly.
^C09:41:44.891 | INFO    | prefect.runner - Pausing schedules for all deployments...
Traceback (most recent call last):
  File "/Users/tejas/Desktop/tinkering/prefect_learning/deployments.py", line 17, in <module>
    get_repo_info.serve(
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/utilities/asyncutils.py", line 259, in coroutine_wrapper
    return call()
           ^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 407, in __call__
    return self.result()
           ^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 285, in result
    return self.future.result(timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 169, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/anaconda3/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/_internal/concurrency/calls.py", line 364, in _run_async
    result = await coro
             ^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/flows.py", line 788, in serve
    await runner.start(webserver=webserver)
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 366, in start
    async with self as runner:
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 1150, in __aexit__
    await self._pause_schedules()
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/runner/runner.py", line 680, in _pause_schedules
    await self._client.update_schedule(deployment_id, active=False)
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/client/orchestration.py", line 1604, in update_schedule
    await <http://self._client.post|self._client.post>(
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1877, in post
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1559, in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/client/base.py", line 282, in send
    response = await self._send_with_retry(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/prefect/client/base.py", line 216, in _send_with_retry
    response = await request()
               ^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1646, in send
    response = await self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1674, in _send_handling_auth
    response = await self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1711, in _send_handling_redirects
    response = await self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_client.py", line 1748, in _send_single_request
    response = await transport.handle_async_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpx/_transports/default.py", line 371, in handle_async_request
    resp = await self._pool.handle_async_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 216, in handle_async_request
    raise exc from None
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_async/connection_pool.py", line 196, in handle_async_request
    response = await connection.handle_async_request(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 99, in handle_async_request
    raise exc
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 76, in handle_async_request
    stream = await self._connect(request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_async/connection.py", line 122, in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_backends/auto.py", line 30, in connect_tcp
    return await self._backend.connect_tcp(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/httpcore/_backends/anyio.py", line 114, in connect_tcp
    stream: anyio.abc.ByteStream = await anyio.connect_tcp(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/anyio/_core/_sockets.py", line 221, in connect_tcp
    await event.wait()
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 1778, in wait
    if await self._event.wait():
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tejas/anaconda3/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
  File "/Users/tejas/Desktop/tinkering/prefect_learning/venv/lib/python3.11/site-packages/greenback/_impl.py", line 211, in _greenback_shim
    next_send = outcome.Value((yield next_yield))
                               ^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError
Here is my setup. I am working within a venv called venv, with Python 3.11.3, and the prefect 2.15.0
Copy code
(venv) (base) ➜  prefect_learning git:(master) ✗ python --version
Python 3.11.3
(venv) (base) ➜  prefect_learning git:(master) ✗ prefect --version
2.15.0
And I can’t seem to reproduce this kind of a stack trace. More often than not it exits cleanly, but every now and then it floods my console with the above logs. Maybe I’m doing thing wrong.
Either way, this is not a problem. Just something that surprised me.
I will continue trudging on with the tutorial. 😄
n
thanks for the detail! 🙏 I'll keep my eye out for similar things