Centos 8 and Python threading
Posted: 2020/09/15 11:22:53
Hello:
I am trying to run the following python code:
This code simulate a race condition, works fine on Mac, Windows and FreeBSD but not Centos. In Centos, the 2 threads run but they don't seems to finish. ie.e the second logging info in the function update is never reached. The script exits fine.
I no longer have Centos now, but would like to know what is wrong. I also updated Python to 3.8 with same results.
Centos installation is standard, no configuration whatsoever. Updated to latest Centos.
I am trying to run the following python code:
Code: Select all
import concurrent.futures
import logging
import time
class FakeDatabase:
def __init__(self):
self.value = 0
def update(self, name):
logging.info("Thread %s: starting update", name)
local_copy = self.value
local_copy += 1
time.sleep(0.1)
self.value = local_copy
logging.info("Thread %s: finishing update", name)
if __name__ == "__main__":
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO,
datefmt="%H:%M:%S")
database = FakeDatabase()
logging.info("Testing update. Starting value is %d.", database.value)
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
for index in range(2):
executor.submit(database.update, index)
logging.info("Testing update. Ending value is %d.", database.value)
I no longer have Centos now, but would like to know what is wrong. I also updated Python to 3.8 with same results.
Centos installation is standard, no configuration whatsoever. Updated to latest Centos.