kandi X-RAY | BackgroundTasks Summary
kandi X-RAY | BackgroundTasks Summary
BackgroundTasks
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of BackgroundTasks
BackgroundTasks Key Features
BackgroundTasks Examples and Code Snippets
Community Discussions
Trending Discussions on BackgroundTasks
QUESTION
I'm defining and endpoint as follows:
...ANSWER
Answered 2021-Aug-16 at 17:52You can make the background_tasks
as a keyword-argument as
QUESTION
According to this tutorial you can create BackgroundTasks
from the route function as follow:
ANSWER
Answered 2021-Nov-17 at 13:38BackgroundTasks
is just a helper, you can run it in thread/loop by yourself:
QUESTION
I am using fast API to do predictions of an ml model. When I give a task_id and input it should add it to the background task and return the response accordingly but I am getting Error 500
when I try to do it.
After adding task_id_globally
it started throwing errors before it worked fine.
Error
ANSWER
Answered 2022-Mar-19 at 10:21You have set task_id_global
to None
, and thus, when calling /predict_solubility
endpoint, it is trying to retrieve an element from the list using response_name[None]
; hence, the error. So you should set task_id_global
to 0
, which should point to some default value in your response_name
list - even if /predict
endpoint has not yet been called - or perform a check inside the second endpoint to see whether task_id_global
is not None
and then decide whether to proceed retrieving an item from the list. Next, inside /predict
endpoint declare task_id_global
as global before using it (using the global
keyword), as, in the way it is currently declared, it is interpreted as a local variable, and hence, the global one never gets affected by any changes occur to task_id_global
inside the endpoint (have a look here).
QUESTION
In an ASP.net core application I spawn background tasks in one request, which can finish by themselves, or be cancelled by a second request. I have the following implementation, but I feel there should be a better way of achieving what I want? Does somebody have some experience with this problem?
...ANSWER
Answered 2022-Mar-18 at 14:55There is a race condition in the code below:
QUESTION
I'm getting inconsistent results when using the Background Tasks framework for my application written in SwiftUI. I'm only looking to make quick network requests, so I'm choosing to use BGAppRefreshTask
.
Background fetch, and Background Processing are set in Signing & Capabilities. Permitted background task scheduler identifiers have been set. Manually calling it in debugging works fine on a real device but never in production.
I tested both BGAppRefreshTask
, and BGProcessingTask
. I noticed BGProcessingTask is being called but only when connected to a power supply. I never see any updates from BGAppRefreshTask
. I'm not sure if I'm missing something simple.
BGAppRefreshTask hasn't run for FOUR days now since updating this post. BGProcessingTask was run 13 time's overnight but only if my device is charging. Even when setting requiresExternalPower
to false.
BGAppRefreshTask run: 0
& BGProcessingTask run: 13
Calling in the debugger using commands here works but it's never run on my device without simulating in the debugger.
...ANSWER
Answered 2022-Feb-28 at 20:08So from new understanding of Background Tasks
, I know now it's being scheduled for an earliest date but I was opening the application setting back the date it's scheduled for. I was not waiting past the earlier date scheduled when relaunching the application. Each task will be overwritten when setting the background app refresh task.
QUESTION
I am having a fastapi to do predictions and returing the output as a response but i have implemented input checking where if the user gives unsupported input it returns a Invalid smile
but the problem here is the response dictionary is not replaced.
when i do the prediction i got this response
...ANSWER
Answered 2022-Feb-26 at 05:22The problem is that response
is a global variable so the elements you write into it on your first request still stay there on the second request.
One quickfix would be to clear the response
dict at the beginning of the request to /predict_solubility
:
QUESTION
I'm implementing a background app refresh for a watch app. To initiate the background refresh, I call the function below during my model initiation when ContentView
is loaded:
ANSWER
Answered 2022-Feb-07 at 18:24It appeared that I needed to provide the delegate for SwiftUI explicitly:
QUESTION
Using python 3x on a Mac. I have a FastAPI server with one endpoint. In this endpoint, I want to be able to run some background tasks. After they are completed, make some computation and only then sends an HTTP response.
What I have is the following:
...ANSWER
Answered 2022-Jan-19 at 20:40It doesn't really make sense to wait for background tasks, as they are ran by definition on the background.
If what you want is to run the function that run those tasks synchronously, i.e. not in the background, you can do this:
QUESTION
I am currently developing an API that has several endpoints. One of them is to register data in a database, other endpoints are related to simple CRUD endpoints (get data by id, get all data, delete data, etc).
When the register data endpoint is called, a response is almost immediately given back to the API and then a background task is started, where we fetch the data, unzip it if necessary, etc.
We are using FastAPI and async functions for this. What I have noticed, though, is that the API gets blocked by the execution of the background task. This is especially bad when I am uploading a large file to S3 in one go (not in chunks, for which i use async functions), I have to wait for the end of the upload of the full file before another request can get a response (like when requesting the get all data endpoint)).
I am a nube in parallelism and concurrency, but I was expecting the background task not the block the API.
Any ideas on how I could run this long running background task in a way that it won't block new requests to the API? Would celery be best for this?
Mock example:
...ANSWER
Answered 2022-Jan-13 at 11:03Update: What worked for me what rewriting my background function (and by consequence, most of my code) not to be async (async def to def). This allowed the background task to be run in a separate thread, while allowing the API to still be responsive. Not sure if this is the best option, but it was the only thing that worked right now. In the future we are probably going to look into using celery for this or separating the service that is responsible for the API calls from another service that is responsible for the actual long running background operations.
QUESTION
I have two problems actually. The first is that I am running a background task in my api that is taking an image and predicting on it. . For some reason I cannot store the background task in a variable and return it. I need to do this for the second part of my problem.
API Code:
...ANSWER
Answered 2021-Sep-22 at 12:55I agree with @MatsLindh's comment, you probably need a task queue system like celery to schedule your image prediction tasks. This will also help with separation of concerns, so the application serving HTTP won't have to deal with ML tasks.
So, a background task runs after returning a response first:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install BackgroundTasks
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page