Accessing global variable which filled in @postfork from another class

Author: more

Originally Sourced from: https://stackoverflow.com/questions/62590230/accessing-global-variable-which-filled-in-postfork-from-another-class

I'm trying to access cassandra session which is filled in @postfork method on startup

But I see "HELLO" in stdout and that's mean the function is working

cassandra.py

cassandra_session=None

@postfork
def connect():
    print("HELLO\n\n\n")
    global cassandra_session
    cassandra_session = CassandraDatastore("keyspace")
    cassandra_session.createSession()


class CassandraDatastore(object):
    def __init__(self, keyspace):
        self.cluster = None
        self.session = None
        self.keyspace = keyspace

    def __del__(self):
        self.cluster.shutdown()

    def createSession(self):
        self.cluster = Cluster(contact_points=["localhost"], protocol_version=4,
                               control_connection_timeout=None,
                               max_schema_agreement_wait=10, load_balancing_policy=RoundRobinPolicy())
        self.session = self.cluster.connect(self.keyspace)

    def getSession(self):
        return self.session

I'm trying to access like:

from app.client import cassandra

cassandra.cassandra_session.getSession().prepare("insert into....")

But I got this error:

AttributeError: 'NoneType' object has no attribute 'getSession'

I followed the example on here: https://blog.turret.io/using-cassandra-with-python-and-uwsgi/