python duplicated code execution inside of docker container

Viewed 25

there is something rather strange thing with my code or i just don't understand some python basics

say i have a program that has some libs with function in modules

myapp.py
mylib # directory
    foo.py
    bar.py

each of this modules has function like (for instance foo.py)

fooInstance = None


def bootstrap_foo()
    global fooInstance
    if fooInstance is None:
        logging.info('bootstrapping foo')
        fooInstance = Foo()
    return fooInstance

and in other modules i have

import foo
my_foo = bootstrap_foo()

and so on

i run code and all works very fine in pycharm but when i try to pack this into docker container with

WORKDIR /app

ADD requirements.txt .
RUN pip install -r requirements.txt

COPY myapp.py /app/
COPY mylib/ /app/mylib/

ENTRYPOINT ["python3", "/app/myapp.py"]

and now strange thing happens, in logs i see that code inside of "bootstrap_foo" is executed twice, as if check

if fooInstance is None:

doesn't work at all

what is the subtle difference between pycharm & docker in this relation ? some python command line arguments ?

0 Answers
Related