try: localBulk = engine.create_bulk(localArray, pymargo.bulk.read_write) remoteBulk = Bulk.from_base64(engine, bulk_str) print("Remote bulk deserialized") size = 5 * 7 * localArray.itemsize engine.transfer(pymargo.bulk.pull, handle.get_addr(), remoteBulk, 0, localBulk, 0, size) except Exception as error: print("An exception was caught:") print(error) print("Transfer done") print("Received: ") print(localArray) handle.respond("OK") engine.finalize() def WhenFinalize(): print("Finalize was called") engine = Engine('tcp') provider_id = 42 print("Server running at address " + str(engine.addr()) + " with provider_id " + str(provider_id)) engine.on_finalize(WhenFinalize) provider = HelloProvider(engine, provider_id) engine.wait_for_finalize()
class ProvDB(): def __init__(self, pdb_path='', pdb_sharded_num=0, pdb_addr=''): if pdb_addr == '': # Standalone mode, need to create engine provider self.pdb_engine = Engine('ofi+tcp', mode=pymargo.server) self.pdb_provider = SonataProvider(self.pdb_engine, 0) self.pdb_address = str(self.pdb_engine.addr()) self.pdb_admin = SonataAdmin(self.pdb_engine) self.pdb_client = SonataClient(self.pdb_engine) if pdb_path and int(pdb_sharded_num) > 0: for i in range(int(pdb_sharded_num)): pdb_name = 'provdb.' + str(i) file_name = pdb_path + pdb_name + '.unqlite' self.pdb_admin.attach_database( self.pdb_address, 0, pdb_name, 'unqlite', "{ \"path\" : \"%s\" }" % file_name) else: # Other Chimbuko module created the engine self.pdb_engine = Engine(pdb_addr.split(':')[0], pymargo.client) self.pdb_address = pdb_addr self.pdb_client = SonataClient(self.pdb_engine) self.pdb_databases = [] self.pdb_collections = [] self.pdb_names = [] for i in range(pdb_sharded_num): pdb_name = 'provdb.' + str(i) self.pdb_names.append(pdb_name) database = self.pdb_client.open(self.pdb_address, 0, pdb_name) self.pdb_databases.append(database) col = database.open('anomalies') self.pdb_collections.append(col) # print("=-=-=-=-=Initiated ProvDB instance {}=-=-=-=-=".format( # self.pdb_address)) def __del__(self): if self.pdb_databases: for database in self.pdb_databases: del database database = None del self.pdb_databases self.pdb_databases = [] if self.pdb_collections: for col in self.pdb_collections: del col col = None del self.pdb_collections self.pdb_collections = [] if self.pdb_names: for name in self.pdb_names: if hasattr(self, 'pdb_admin'): self.pdb_admin.detach_database(self.pdb_address, 0, name) del name name = None self.pdb_names = [] if self.pdb_client: del self.pdb_client self.pdb_client = None if self.pdb_address: del self.pdb_address self.pdb_address = None if hasattr(self, 'pdb_admin') and self.pdb_admin: del self.pdb_admin self.pdb_admin = None if hasattr(self, 'pdb_provider') and self.pdb_provider: del self.pdb_provider self.pdb_provider = None if self.pdb_engine: self.pdb_engine.finalize() gc.collect() del self.pdb_engine self.pdb_engine = None