## Python 3.x – The Uvicorn server shuts down unexpectedly

I am working with the FastAPI framework, served by the Uvicorn server.
My application should execute some numerical calculation that consumes a lot of time in a final point (/ execute). For this I am using & # 39; background_task & # 39; of fastAPI (which is basically & # 39; background_task & # 39; from Starlette).

When executing the application, after some moments of nominal behavior, the server shuts down for some reason.

The application records look like this:

``````INFO: server process started [922]
INFO: Waiting for the start of the application.
DEBUG: None - ASGI [1] Started
DEBUG: None - ASGI [1] Sent {& # 39; type & # 39 ;: & # 39; lifespan.startup & # 39;}
DEBUG: None - ASGI [1] Received {& # 39; type & # 39; lifespan.startup.complete & # 39;}
INFO: Uvicorn runs on http://0.0.0.0:8000 (Press CTRL + C to exit)
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - Connected
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57397) - Connected
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [2] Started
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [2] Received {& # 39 ;: & # 39; http.response.start & # 39 ;, & # 39 ;: & # 39 ;: 200, & # 39; headlines & # 39 ;: & # 39;<...>& # 39;
INFO: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - "GET / run HTTP / 1.1" 200
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [2] Received {& # 39; type & # 39 ;: & # 39; http.response.body & # 39 ;, & # 39; body & # 39 ;: & # 39;<32 bytes>& # 39;
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [3] Started
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [3] Received {& # 39 ;: & # 39; http.response.start & # 39 ;, & # 39 ;: & # 39 ;: 404, & # 39; headlines & # 39 ;: & # 39;<...>& # 39;
INFO: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - "GET /favicon.ico HTTP / 1.1" 404
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [3] Received {& # 39; type & # 39 ;: & # 39; http.response.body & # 39 ;, & # 39; body & # 39 ;: & # 39;<22 bytes>& # 39;
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [3] Finished

...

DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - Offline
... The background task is complete.
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57396) - ASGI [2] Finished
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57397) - Offline
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57405) - Connected

...
The application continues, with requests and background tasks completed.
At some point, during the execution of a task in the background:

INFO: turning off
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57568) - Offline
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57567) - Offline
INFORMATION: Pending completion of tasks in the background. (CTRL + C to force the exit)
DEBUG: (& # 39; 10 .0.2.111 & # 39 ;, 57567) - ASGI [6] Finished
INFO: Waiting for the application to close.
DEBUG: None - ASGI [1] Sent {& # 39; type & # 39 ;: & # 39; lifespan.shutdown & # 39;}
DEBUG: None - ASGI [1] Received {& # 39 ;: & # 39; lifespan.shutdown.complete & # 39;}
DEBUG: None - ASGI [1] Finished
INFO: Process of the finished server [922]
``````

I really do not understand why this happens. I have no idea what to try to fix it.

My code looks like this.

``````#! / usr / bin / env python3.7
import time
import uvicorn
from starlette.responses import JSONResponse
import my_imports_from_project

analysis_api = FastAPI ()

@ analysis_api.get ("/")
Async def root ():
returns {"message": "root"}

@ analysis_api.get ("/ test")
async def test ():
returns {"message": "test"}

@ analysis_api.get ("/ run")
try:
some_checks (name)
except RaisedExceptions:
body = {"running": False,
"name name,
return JSONResponse (state_code = 400, content = body)
body = {"running": True,
"name name}
return JSONResponse (state_code = 200, content = body)

yes __name__ == "__main__":
uvicorn.run ("api: analysis_api", host = "0.0.0.0", log_level = "debug")

``````

## elliptic curve (y ^ 2 = x ^ 3 + 3x +8) (mod 13) – torsion groups

Corollary 6.4. Leave $$E$$ be an elliptical curve and leave $$m en mathbb {Z}$$ with $$m ne 0$$.

(b) yes $$m ne 0$$ in $$K$$, that is, if any $$operatorname {char} (K) = 0$$ or $$p: = operatorname {char} (K)> 0$$ Y $$p nmid m$$, so $$E[m] = mathbb {Z} / m mathbb {Z} times mathbb {Z} / m mathbb {Z}$$.

(page 86 of [Silverman, The Arithmetic of Elliptic Curves, 2nd Edition])

Leave $$E: y ^ 2 = x ^ 3 + 3x + 8$$ finished $$mathbb {Z} / 13 mathbb {Z}$$. I just calculated the points on this curve. exist $$# E[3] stackrel {?} {=} 2$$ order points $$3$$ Y $$# E[9] stackrel {?} {=} 6$$ Points of order 9.

(i) expected $$9$$ order points $$3$$, as $$# E[3] = # left ( mathbb {Z} / 3 mathbb {Z} times mathbb {Z} / 3 mathbb {Z} right) = 9$$. Because there is only $$2$$ order points $$3$$?

(ii) I calculated $$# E ( mathbb {Z} / 13 mathbb {Z}) = 9$$ (by brute force). So I understand the above Corollary 6.4, there must be some points of order $$5$$, as $$p = 13 nmid 5$$. But the existence of such a point $$P in E[5]$$ would imply the existence of some subgroup $$langle P rangle leq E ( mathbb {Z} / 13 mathbb {Z})$$ With order $$5$$ as well. This can not happen, since the order of a subgroup must divide the order of the upper group. As $$5 nmid 9$$, there can be no points of order $$5$$.

What am I missing?

## python 3.x – How do the loop runners (presumably synchronized) start the loop of asynchronous events?

Where is the implementation interface in Python documented that allows asynchronous loop brokers (trio, asyncio, curio) to start all the shebang?

We know that synchronization functions can not call asynchronous functions, and yet, asynchronous implementations have a magic function that starts the entire event loop, for example:

``````trio.run (some ... asynchronous ... fun) ...

docstring: except that: func: `run` can (and should) be called from a synchronous context.
``````

Google & # 39; python start an async event loop & # 39; it refers to asyncio documentation, which is a specific implementation.

Are the asyncio / trio / curio loop runners crafted to break the sync-> async wall?

## python 3.x – I have dictionaries in one of the columns and I need to fit this into a Logistic Regression model

This is one of the columns of my training data. The training data has 3 more columns. But I only show one here because this column is taking up too much space.

``````the word count
1 {& # 39; it & # 39 ;: 2, & # 39 ;: 1, & # 39; early & # 39 ;: 1, & # 39 ;: 3, & # 39; wa ...
2 {& # 39; Very & # 39 ;: 1, & # 39; smooth & # 39 ;: 1, & # 39 ;: 2, & # 39; comfortable & # 39; ...
3 {& # 39; This & # 39 ;: 1, & # 39 ;: 4, & # 39 ;: 2, & # 39; product & # 39 ;: 2, & # 39; we ...
4 {& # 39; All & # 39 ;: 1, & # 39 ;: 1, & # 39 ;: 1, & # 39; kids & # 39 ;: 2, & # 39; have & # 39; ...
5 {& # 39; When & # 39 ;: 1, & # 39 ;: 5, & # 39; Binky & # 39 ;: 3, & # 39; Hada & # 39 ;: 3, ...
``````

Now I am trying to adjust this data frame and the following error message:

``````from sklearn.linear_model import LogisticRegression
model = LogisticRegression (). fit (X_train, y_train)

The TypeError: float () argument must be a string or a number, not & dict & # 39;
``````

## sequences and series: \$ 1 + 2x + 3x ^ 2 + points \$ converge to what?

Assuming the following terms are the following, you must have:

$$1 + 2x + 2x ^ 2 + cdots + 2x ^ n$$
$$= left (1 + x + x ^ 2 + cdots + x ^ n right) + left (x + x ^ 2 + cdots + x ^ n right)$$

instead of $$Sigma_ {n = 0} ^ infty nx ^ n$$.

Now you can use the formula for an infinite sum of a geometric series.

## python 3.x – Interact with a Python3 web page

my doubt was more than anything if you can create a program in python to interact within a web page. For example, on Facebook, from the program I tell you to open the index page of the web in question and enter the logeo data, and then open a chat x and send a message. Can this kind of thing be done in Python 3? It does not matter if you have to install external modules. Or would it be simpler in another language? Thank you in advance.

## python 3.x – Draw the entire legend in a loop

Please I need help. I want to trace all the legends in a loop.

P4 = numpy.arange (10,300,1) V44 = {} V7_list = list (V7.values ​​())
for j in range (0, len (per)):
A = ([i[j] for i in V7_list])

``````V44[j]= [i[0] for i in A]TTT =[55,544,4545]            for j in range (0, len (T4)):
plt.plot (V44[j], T4)
legend ((T4[j],))
plt.plot ()
plt.xlabel ("Minimum pressure P4 (atm) for on", font size = 12)
plt.ylabel ("T4 [K]", font size = 12)
plt.plot ()
``````

## python 3.x – Pandas creating and filling new columns based on other columns

I have a panda data frame with columns of time and values. I am trying to create two new columns & # 39; START_TIME "& & # 39; END_TIME & # 39 ;. They are data related to the medication and are poorly stored in the database, so I am trying to transform the table.
In this case, the medication for a patient started at 2018-11-07 23:59:32 with a dose value of 80th, so I want to capture that since the start and end time of the medication is the first zero after the last value. That would be a round of medication. Each time a new value starts, it is considered as the second round of medications and I would like to capture the start time and end time as follows, as explained above.

``````Time values
2018-11-07 23:59:32 80.0
2018-11-08 04:35:09 80.0
2018-11-08 05:31:24 40.0
2018-11-24 18:29:30 0.0
2018-11-24 18:33:14 0.0
2018-11-26 17:39:31 20.0
2018-11-26 18:51:07 20.0
2018-11-26 21:04:35 0.0
2018-11-26 21:05:20 0.0
2018-11-26 21:13:44 0.0
2018-11-26 21:25:57 0.0
2018-11-29 02:19:57 7.0
2018-12-09 16:02:06 5.0
2018-12-09 16:33:03 2.5
2018-12-09 21:02:10 0.0
``````

I think it can not be done with a simple for and if loop, since I started with a simple step and failed

``````for i in df['Values']:
yes i + 1! = 0:
df['START_TIME'] = df['TIME'].copy()
``````

Expected data framework:

``````Time values ​​START_TIME END_TIME
2018-11-07 23:59:32 80.0 2018-11-07 23:59:32
2018-11-08 04:35:09 80.0
2018-11-08 05:31:24 40.0
2018-11-24 18:29:30 0.0 2018-11-24 18:29:30
2018-11-24 18:33:14 0.0
2018-11-26 17:39:31 20.0 2018-11-26 17:39:31
2018-11-26 18:51:07 20.0
2018-11-26 21:04:35 0.0 2018-11-26 21:04:35
2018-11-26 21:05:20 0.0
2018-11-26 21:13:44 0.0
2018-11-26 21:25:57 0.0
2018-11-29 02:19:57 7.0 2018-11-29 02:19:57
2018-12-09 16:02:06 5.0
2018-12-09 16:33:03 2.5
2018-12-09 21:02:10 0.0 2018-12-09 21:02:10
``````

I would really appreciate it if I can get some help.

## Python 3.x: How can I download the encoded images from the mentioned websites?

I am trying to discard images from the site using python (beautifulsoup)
url = https://mahabhunakasha.mahabhumi.gov.in/bhunaksha/27/index.jsp

I want to download all the images from the websites of all the areas using python.

I tried the following code:

``````import urllib
import urllib.request
from bs4 import BeautifulSoup
import base64
OS import
of the ascii_lowercase import chain

def make_soup (url):
thepage = urllib.request.urlopen (url)
soupdata = BeautifulSoup (thepage, "html.parser")
come back soupdata
# soup = make_soup ("https://mahabhunakasha.mahabhumi.gov.in/bhunaksha/27/index.jsp")
soup = make_soup ("https://www.makemytrip.com")
print (soup)
# for img in soup.findAll ("src"):
# print (img)
``````

So let's find out how to do it. That link in the image is encoded with base 64.

## python 3.x – Countdown on the computer

I want to make a program in piton in that if the user does not execute a certain action in, for example, 30 minutes, he removes himself from the machine. How can I do that "countdown"? How do the programs with a "Trial" license do it? Any help is welcome.