Docker Community Forums

Share and learn in the Docker community.

Issues for implementing before_request decorator in Flask docker_container

HI ,
i am using docker compose in order to create an Service Oriented architecture for a virtual drone .
I am facing some difficulties . Since i have to make the connection with the drone , using Flask it is recommended to use the before_request decorator , this last one can be also use to make the connection for the database or any operation that should be done before any request .
I tried my code with Docker and without :
1-without docker there is no issues the request is working and i am able to send command to the drone
2-when i run the code into the docker image the request is partially working , and i am not able to fulfill the operation or some commands no more . For example i can even print a string message

here is my code
precision it works well without docker :

from dronekit import connect ,VehicleMode,LocationGlobalRelative
from flask import Flask, request
import time,socket,threading,json

global varaibale that will be use for handling the drone object


class Drone:
def init(self,vehicle):
self.vehicle = vehicle

def set_vehicle_mode(self,mode):
    return "vehicle mode changed with success"

def get_vehicle(self):
    return self.vehicle

def get_vehicle_mode(self):

app = Flask(name)

Threads that will be used to handle some request


def func():
print("this must run before any request ")

def index():
return “welcome to dronekit sitl service”

def test():
return “welcome to dronekit sitl 4444 service”

if name == ‘main’:‘’,debug=True)

1 Like

I am having the same issue, were you ever able to find the fix?