Accessing global variable which filled in @postfork from another class

Author: more

Originally Sourced from:

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


def connect():
    global cassandra_session
    cassandra_session = CassandraDatastore("keyspace")

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

    def __del__(self):

    def createSession(self):
        self.cluster = Cluster(contact_points=["localhost"], protocol_version=4,
                               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: