Exemple #1
0
def database_connection():
    """Sets up a database connection if it has not been set up yet in this process and returns said connection."""
    global _database_connection
    global _current_process_id
    if not _database_connection or os.getpid() != _current_process_id:
        _database_connection = ZEO.connection(_database_address)
        _current_process_id = os.getpid()
        transaction.begin()
        # print(f"PID {os.getpid()}: Created new DB connection: {_database_connection} connecting to {_database_address}")
    # else:
    # print(f"PID {os.getpid()}: Returning old DB connection {_database_connection}")
    return _database_connection
def connectZEO(host='docker-compose_zeo_1', port=8090):
    '''
    Input:
    host - host server
    port - port to connect to
    
    Output:
    returns database-root
    '''

    # To connect to ZEO
    import ZEO

    # Connect to ZODB
    connection = ZEO.connection((host, port))
    return connection.root()
Exemple #3
0
import ZEO

adr, stop = ZEO.server(path='127.0.0.1', port=8018)
print(adr)
connection = ZEO.connection(adr)
client_storage = ZEO.client(adr)
stop()