question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

After executing first request, rest of the request got stuck till the first one is executed

See original GitHub issue

##  IN MY app/repository/connector.py  

import os
import sys
import psutil


async def get_all_lines(loc="xyz.log"):
    try:
        with open(loc) as read_file:
            all_lines = read_file.readlines()
            all_lines = list(map(lambda s: s.strip(), all_lines))
            all_lines = [s for s in all_lines if s]
        return all_lines[-1].split("-")[0].split(",")[0]
    except Exception as e:
        return "[ERROR] Unable to process file {}".format(loc)


async def checkIfProcessRunning(processName):
    for proc in psutil.process_iter():
        try:
            if processName.lower() in proc.name().lower():
                return True
        except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
            pass
    return False

async def get_running_status(processes=['ABC', 'chrome.exe', "java"]):
    status = ""
    for process in processes:
        if await checkIfProcessRunning(process):
            status += "{} is in running state\n".format(process)
        else:
            status += "{} is NOT in running state\n".format(process)
    return status

##  IN MY app/router/connection.py  

from fastapi import APIRouter, Depends, status, HTTPException
from .. import schemas, oauth2
from typing import List
from .. repository import connector

router = APIRouter(
    tags=['connector'],
    prefix="/connector"
)


@router.get('/', status_code=200)
async def show(current_user = Depends(oauth2.get_current_user)):
    status = await connector.get_all_lines()
    return {"last_connected_at": status}

@router.get('/process_running_status', status_code=200)
async def show(current_user = Depends(oauth2.get_current_user)):
    status = await connector.get_running_status()
    return {"process_status": status}

Description

  • Open the browser and I call the endpoint /process_running_status.
  • It returns a { “process_status”: "ABC is NOT in running state\nchrome.exe is in running state\njava is in running state }` but takes sometime to respond
  • But when this is executing, my all other requests to the API are on hold till it gets completed. Am i doing this right way?
  • I want if this request /process_running_status is running, it should not hold the other request.

Environment

  • OS: Windows:

  • FastAPI Version: 0.63.0

  • Python version: Python3.9

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
vik03commented, May 14, 2021

Also, any help is much appreciated. @tiangolo or anyone from this community. I request all of you to Please look into this on priority

Read more comments on GitHub >

github_iconTop Results From Across the Web

request.get() is getting stuck - python - Stack Overflow
Answer: Sometimes requests from requests.get() gets blocked by server, so solution is to make the server think the request is coming from a ......
Read more >
Troubleshoot invocation issues in Lambda
When you invoke a Lambda function, Lambda validates the request and ... There is a known issue in which the first invocation on...
Read more >
Why your multiprocessing Pool is stuck (it's full of sharks!)
You're using multiprocessing to run some code across multiple processes, and it just—sits there. It's stuck.
Read more >
Troubleshoot Dataflow errors - Google Cloud
When you try to run a Dataflow job, the following error occurs: Some Cloud APIs need to be enabled for your project in...
Read more >
Complete Guide to Spring RestTemplate - Reflectoring
getForEntity() : executes a GET request and returns an object of ... To work with the examples of using RestTemplate , let us...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found