<@ULVA73B9P> can I avoid having to run that `serve...
# ask-marvin
d
@Marvin can I avoid having to run that
serve()
on a
while True
? I don't know what's causing a
RuntimeError
and it stops my code, so I needed to rerun constantly.
Copy code
@flow(retries=3, retry_delay_seconds=5, log_prints=True)
def get_repo_info(repo_name: str = "PrefectHQ/prefect"):
    ...


if __name__ == "__main__":
    while True:
        try:
            get_repo_info.serve(name="my-first-deployment")
        except RuntimeError as e:
            if e.args == ("this borrower is already holding one of this CapacityLimiter's tokens",):
                print("Ran into that 'CapacityLimiter's tokens' issue. Restarting.")
                continue
            raise e
m
It seems like you're running into a
RuntimeError
due to some issue with
CapacityLimiter's tokens
. This might be related to resource allocation or rate limits in Prefect. 1. Resource Allocation: Make sure to allocate enough CPU and memory to your agent. Your agent needs enough resources to appropriately provision infrastructure for your flow runs and to monitor their execution. Otherwise, your flow runs may get stuck in a pending state. [^1^] 2. Rate Limits: API rate limits restrict the number of requests that a single client can make in a given time period. They ensure Prefect Cloud's stability, so that when you make an API call, you always get a response. Prefect Cloud rate limits are subject to change. Contact Prefect support at help@prefect.io if you have questions about current rate limits. [^3^] However, these are just general suggestions. The specific issue you're facing might be due to some other reason. If you could provide more details about the error and the context in which it's occurring, I might be able to help you better. [^1^]: Prefect Docs - Infrastructure [^3^]: Prefect Docs - API Rate Limits &amp; Retention Periods
n
hey @Diego Lima - you shouldnt have to put .serve in a while loop like that
yess 1
d
i'm running all locally (no prefect cloud involved). i'm not running any heavy workload. so i don't think it's related to resource allocation or rate limiting
i'm just testing things out
c
ah this isn't well documented but there's a process limit setting that doesn't allow more than a certain number of subprocesses running at one time.
it can be set via enviroment variable
PREFECT_RUNNER_PROCESS_LIMIT
it defaults to 5
n
i believe if you use
from prefect import serve
instead of the
Flow
method, it will also accept
limit
as a kwarg
upvote 2
d
that'd make sense. but if I run into that limit at any point, I think I shouldn't have to restart my script. wdyt?
i mean I can increase that limit, but there's no guarantee I'll never reach it so I'd have to keep checking if my script hasn't died
c
you shouldn't need to; it shouldn't error out so maybe there's a bug somewhere in here
d
agree
all I did was run the tutorial example (snippet attached) with an input I knew would error (e.g: _`repo_name="asasdasd"`_) and set retry to some number (e.g.
5
)
c
would you mind opening an issue for this?
d
will do!
thank you 1
don't know how you guys are prioritizing these issues but this one manifested while following official docs, so that's something
c
thank you! we can most likely get this into next week's release