What is a Recommended Practice for Handling Asynchronous Requests with Long-Running Processes with Flask?

Problem scenario
You are designing a Flask application with Python running some long-running processes. You want to handle the requests asynchronously. The individual requests will have a duration of more than one hour. What is the recommended way of handling this?

Solution
Use a task queue like Celery or RQ (Redis Queue).

Sources:
https://stackoverflow.com/questions/42790362/how-to-handle-long-sql-query-in-flask

Flask API app for long running process?

How Do You Use Custom Resource Definitions in Kubernetes?

Problem scenario
You want to extend Kubernetes’ functionality. You want to use CustomResourceDefinitions. You can view API resources by running “kubectl api-resources”. You want to add to the list. How do you use a CRD?

Solution

  1. Create a file called contint.yaml with the following content:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: contintexamples.continualintegration.com
spec:
group: continualintegration.com
names:
kind: ContintExample
plural: contintexamples
listKind: ContintExampleList
singular: contintexample
scope: Namespaced
versions:
– name: v1
# Each version can be enabled/disabled by Served flag. …

In The Context of Replication Clusters or Synchronization Backups (Either Cold, Warm, or Hot), what is a Sink?

Question
When you have high availability of servers, you have seen diagrams with a “sink” server. What does the word “sink” signify?

Answer
A sink, homophonic with “sync”, is a secondary server in a cluster or replication configuration. That is, there is a primary server that is actively processing transactions of databases or registering changes to files. This primary server may replicate changes over to a secondary or sink server.

How Do You Troubleshoot “ImportError: No module named ‘pandas'”?

Problem scenario
From a Python command line, you get this message:

Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘pandas’

What should you do?

Solution
Prerequisite
You need pip to be installed. If you need assistance, see this posting.

Procedures
Run one of these commands:

pip install pandas

pip3 install pandas …

How Do You Get Scanned Documents to Be PDFs and Rotated the Way You Prefer in Windows?

You scanned some documents into a Windows machine. One or both of the following apply:

Problem scenario #1
When you right click on them to print them, the print preview is showing them rotated 90 degrees from the orientation you want.

Problem scenario #2
When you right click on them to print them, they print rotated 90 degrees from the orientation that you would prefer.

In Python How Do You Avoid the Inelegant Dictionary Key-Check Logic?

Problem scenario
You try this prog1.py:

book = {}
book[”apple”] = 5
var1 = book[”orange”]

It returns this:

Traceback (most recent call last):
File “prog1.py”, line 3, in
var1 = book[“orange”]
KeyError: ‘orange’

You often see a couple lines of code check if a key exists in a dictionary before a specific action. You want to avoid this and write Python in a more elegant fashion.

What Is the Call Stack, the Kernel Stack and the User Stack?

Question
You have heard of different stacks such as the call, kernel and user stacks.

How are they different?

Answer
“The call stack, or runtime stack, is an area of memory used to store function return information and local variables.” (This was taken from https://developer.arm.com/documentation/101470/2021-2/Examining-the-Target/Examining-the-call-stack)

“The user stack contains the arguments, local variables, and other data for functions executing in user mode.” (Taken from https://www.gotothings.com/unix/user-and-kernel-stack-for-copy-program.htm.)

“The user stack is only used while the process is running in user mode.” (Taken from https://www.baeldung.com/linux/kernel-stack-and-user-space-stack.)

“The kernel stack is a per-process memory region maintained in kernel memory that is used as the stack for execution of the functions called internally during the execution of a system call.” (This was taken from page 122 of Kerrisk’s The Linux Programming Interface book.)

The user stack resides in a different location from the kernel stack (taken from https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack).

Are User Mode and Kernel Mode Different from User Space and Kernel Space Respectively?

Question
You have read about user mode and kernel mode. Are they the different from userspace and kernel space respectively?

Answer
Yes. User space is not the same as user mode. Kernel space is not the same as kernel mode.

“Modern processor architectures typically allow the CPU to operate in at least two different modes: user mode and kernel mode (sometimes also referred to as supervisor mode).” Taken from page 23 of The Linux Programming Interface by Michael Kerrisk.

What Is User Space and Is It Different from the User Stack?

Question
What is user space and is it different from the user stack? If the user stack is part of the user space, what else does user space have besides the user stack?

Answer
User space is a portion of memory of an Operating Systems that is not designated for kernel space. System calls enable user processes to enter kernel space. To read more about a system call,

What Is Kernel Space and Is It Different from the Kernel Stack?

Question
What is kernel space and is it different from the kernel stack?

Answer
“System memory in Linux can be divided into two distinct regions: kernel space and user space. Kernel space is where the kernel (i.e., the core of the operating system) executes (i.e., runs) and provides its services. “

Kernel space is mutually exclusive with user space (according to https://unix.stackexchange.com/questions/87625/what-is-difference-between-user-space-and-kernel-space,