### Create and Connect to UltraDict Instance Source: https://context7.com/ronny-rentner/ultradict/llms.txt Demonstrates creating a new UltraDict with initial data and connecting to an existing one from another process using its shared memory name. Includes examples for explicit naming, Windows compatibility, and custom serializers. ```python from UltraDict import UltraDict # Create a new UltraDict with initial data ultra = UltraDict({'key1': 'value1', 'key2': 42}, buffer_size=10_000) print(f"Created UltraDict with name: {ultra.name}") # Output: Created UltraDict with name: psm_a1b2c3d4 # Connect to existing UltraDict from another process other = UltraDict(name=ultra.name) print(other) # Output: {'key1': 'value1', 'key2': 42} ``` ```python # Create with explicit name and ensure it's new (raises AlreadyExists if exists) ultra_named = UltraDict(name='my-shared-dict', create=True, buffer_size=50_000) ``` ```python # Windows-compatible setup with static full dump size ultra_win = UltraDict( buffer_size=10_000, shared_lock=True, # Required for spawn context full_dump_size=10_000 # Static memory for Windows compatibility ) ``` ```python # Use custom serializer (must support loads() and dumps()) import marshal ultra_marshal = UltraDict(serializer=marshal) ``` -------------------------------- ### Basic Dictionary Operations with UltraDict Source: https://context7.com/ronny-rentner/ultradict/llms.txt Shows standard Python dictionary operations like getting length, checking for keys, iterating, updating, and deleting items. Changes are automatically synchronized across processes. ```python from UltraDict import UltraDict # Create and populate dictionary ultra = UltraDict() ultra['counter'] = 0 ultra['name'] = 'shared data' ultra['items'] = [1, 2, 3] # Standard dict operations print(len(ultra)) # Output: 3 print('counter' in ultra) # Output: True print(ultra.keys()) # Output: dict_keys(['counter', 'name', 'items']) print(ultra.values()) # Output: dict_values([0, 'shared data', [1, 2, 3]]) # Update values ultra['counter'] += 1 print(ultra['counter']) # Output: 1 # Delete items del ultra['items'] print(ultra) # Output: {'counter': 1, 'name': 'shared data'} # Batch update ultra.update({'a': 1, 'b': 2, 'c': 3}) # Access underlying local cache for maximum read performance (no real-time sync) raw_data = ultra.data print(raw_data['counter']) # Direct access, factor ~15 faster ``` -------------------------------- ### Initialize UltraDict and Demonstrate Buffer Behavior Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Initializes an UltraDict with specific buffer size and name. Demonstrates how data exceeding the buffer size, including serialization overhead, affects buffer status. ```python >>> ultra = UltraDict({ 'init': 'some initial data' }, name='my-name', buffer_size=100_000) >>> # Let's use a value with 100k bytes length. >>> # This will not fit into our 100k bytes buffer due to the serialization overhead. >>> ultra[0] = ' ' * 100_000 >>> ultra.print_status() ``` -------------------------------- ### Populate and Access UltraDict in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Demonstrates populating an UltraDict with a large number of key-value pairs and accessing an element. ```python from UltraDict import UltraDict ultra = UltraDict() for i in range(10_000): ultra[i] = i len(ultra) ultra[500] ``` -------------------------------- ### Initialize UltraDict in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Create an UltraDict instance with initial data. The shared memory name is accessible via the `.name` attribute for connecting from other processes. ```python from UltraDict import UltraDict ultra = UltraDict({ 1:1 }, some_key='some_value') ultra ultra.name ``` -------------------------------- ### Initialize Comparison Data Structures in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Initializes a standard Python dictionary, a multiprocessing Manager dictionary, and a Redis instance for performance comparison. ```python from UltraDict import UltraDict import multiprocessing, redis, timeit ultra = UltraDict() for i in range(10_000): ultra[i] = i orig = dict(ultra) len(orig) orig[500] managed = multiprocessing.Manager().dict(orig) len(managed) r = redis.Redis() r.flushall() r.mset(orig) ``` -------------------------------- ### Using UltraDict Lock with Different Options Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Demonstrates various ways to use the UltraDict lock, including default settings, custom timeouts, busy-waiting, and non-blocking acquire attempts. Ensure `shared_lock=True` is set for `SharedLock` usage, which requires the `atomics` package. ```python ultra = UltraDict(shared_lock=True) with ultra.lock: ultra['counter']++ ``` ```python # The same as above with all default parameters with ultra.lock(timeout=None, block=True, steal=False, sleep_time=0.000001): ultra['counter']++ ``` ```python # Busy wait, will result in 99 % CPU usage, fastest option # Ideally number of processes using the UltraDict should be < number of CPUs with ultra.lock(sleep_time=0): ultra['counter']++ ``` ```python try: result = ultra.lock.acquire(block=False) ultra.lock.release() except UltraDict.Exceptions.CannotAcquireLock as e: print(f'Process with PID {e.blocking_pid} is holding the lock') ``` ```python try: with ultra.lock(timeout=1.5): ultra['counter']++ except UltraDict.Exceptions.CannotAcquireLockTimeout: print('Stale lock?') ``` ```python with ultra.lock(timeout=1.5, steal_after_timeout=True): ultra['counter']++ ``` -------------------------------- ### Constructor: Ultradict Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Initializes a new Ultradict instance, allowing for shared memory dictionary creation or attachment. ```APIDOC ## Constructor: Ultradict ### Description Initializes the Ultradict object. This class manages shared memory dictionaries across multiple processes. ### Parameters #### Request Body - **name** (string) - Optional - Name of the shared memory. A random name is chosen if not set. - **create** (boolean) - Optional - If True, creates a new UltraDict; throws an exception if it exists. If None, creates or attaches. - **buffer_size** (integer) - Optional - Size of the shared memory buffer for streaming changes. Defaults to 10000. - **serializer** (object) - Optional - Serializer module/object (must support loads() and dumps()). Defaults to pickle. - **shared_lock** (boolean) - Optional - If True, uses a shared lock for synchronization across independent processes. - **full_dump_size** (integer) - Optional - If set, uses static full dump memory instead of dynamic allocation. - **auto_unlink** (boolean) - Optional - If True, the creator automatically unlinks the handle at exit. - **recurse** (boolean) - Optional - If True, nested dict objects are automatically wrapped in an UltraDict. - **recurse_register** (string/object) - Optional - Used internally to track recursive UltraDicts for cleanup. ``` -------------------------------- ### Manage Memory and Cleanup Source: https://context7.com/ronny-rentner/ultradict/llms.txt Demonstrates automatic cleanup via auto_unlink and manual resource release using the close method. ```python from UltraDict import UltraDict # auto_unlink=True (default for creator) - cleans up when process exits ultra = UltraDict(name='temp-dict', auto_unlink=True) ultra['data'] = 'temporary' # Explicit cleanup - returns data as regular dict data = ultra.close() print(data) # Output: {'data': 'temporary'} ``` -------------------------------- ### Initialize UltraDict with Custom Serializer Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Initializes an UltraDict using a custom serializer, such as `jsons`. The custom serializer must implement `loads()` and `dumps()` methods compatible with UltraDict's requirements. ```python >>> # Use any serializer you like, given it supports the loads() and dumps() methods >>> import jsons >>> ultra = UltraDict(serializer=jsons) ``` -------------------------------- ### Configure UltraDict for Spawned Processes Source: https://context7.com/ronny-rentner/ultradict/llms.txt Initializes an UltraDict instance with shared_lock enabled, which is necessary for cross-process communication in spawn contexts. ```python ultra_spawn = UltraDict( buffer_size=10_000, shared_lock=True, full_dump_size=10_000 ) ultra_spawn['counter'] = 0 def worker_spawn(name, iterations): d = UltraDict(name=name, shared_lock=True) for _ in range(iterations): with d.lock: d['counter'] += 1 ``` -------------------------------- ### Perform Full Data Dump with UltraDict Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Creates a full dump of the current UltraDict state to persistent storage. This is useful for saving the entire dictionary content. ```python >>> # Create a full dump >>> ultra.dump() ``` -------------------------------- ### Coordinate Multi-Process Communication Source: https://context7.com/ronny-rentner/ultradict/llms.txt Demonstrates a producer-consumer pattern using shared memory and a shared lock to synchronize access. ```python from UltraDict import UltraDict import multiprocessing def producer(name, items): """Producer process adds items to shared dict""" d = UltraDict(name=name, shared_lock=True) for i, item in enumerate(items): with d.lock: d[f'item_{i}'] = item with d.lock: d['producer_done'] = True def consumer(name, expected_count): """Consumer process reads items from shared dict""" d = UltraDict(name=name, shared_lock=True) results = [] while len(results) < expected_count: with d.lock: for key in list(d.keys()): if key.startswith('item_') and key not in [r[0] for r in results]: results.append((key, d[key])) return results if __name__ == '__main__': # Create shared dict with spawn-safe settings ultra = UltraDict( buffer_size=10_000, shared_lock=True, full_dump_size=10_000 ) ctx = multiprocessing.get_context('spawn') # Start producer items = ['apple', 'banana', 'cherry', 'date'] p = ctx.Process(target=producer, args=[ultra.name, items]) p.start() p.join() # Verify data print(ultra) # Output: {'item_0': 'apple', 'item_1': 'banana', 'item_2': 'cherry', 'item_3': 'date', 'producer_done': True} ``` -------------------------------- ### Connect to Existing UltraDict in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Connect to an existing UltraDict instance in another process using its shared memory name. Modifications made in one process are reflected in others. ```python from UltraDict import UltraDict other = UltraDict(name='psm_ad73da69') other other[2] = 2 ``` -------------------------------- ### Force Load Full Dump and Apply Updates Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Forces the loading of the latest full dump, even if it has already been processed. This can be followed by applying any available streaming updates to synchronize the local dictionary. ```python >>> # Force load of latest full dump, even if we had already processed it. >>> # There might also be streaming updates available after loading the full dump. >>> ultra.load(force=True) >>> # Apply full dump and stream updates to >>> # underlying local dict, this is automatically >>> # called by accessing the UltraDict in any usual way, >>> # but can be useful to call after a forced load. >>> ultra.apply_update() ``` -------------------------------- ### Initialize Recursive UltraDict in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Initialize an UltraDict with recursion enabled. Nested dictionaries will automatically be converted to UltraDict instances. ```python from UltraDict import UltraDict ultra = UltraDict(recurse=True) ultra['nested'] = { 'counter': 0 } type(ultra['nested']) ultra.name ``` -------------------------------- ### Full Dump and Load Operations Source: https://context7.com/ronny-rentner/ultradict/llms.txt Control when full dumps are created and loaded. Full dumps are automatically triggered when the streaming buffer fills up, but can be manually triggered. Use `dump()` to force a dump and `load(force=True)` to load the latest full dump. ```python from UltraDict import UltraDict ultra = UltraDict(name='dump-example', buffer_size=10_000) # Add data for i in range(1000): ultra[i] = f'value_{i}' # Force a full dump to shared memory full_dump_memory = ultra.dump() print(f"Dumped to: {full_dump_memory.name}") # Force load the latest full dump (useful after forced dump) ultra.load(force=True) # Apply any pending updates from stream ultra.apply_update() # Check internal status status = ultra.status() print(f"Stream position: {status['update_stream_position']}") print(f"Full dump counter: {status['full_dump_counter']}") print(f"Buffer size: {status['buffer_size']}") # Pretty print full status ultra.print_status() ``` -------------------------------- ### Recursive Nested Dictionaries with UltraDict Source: https://context7.com/ronny-rentner/ultradict/llms.txt Illustrates how to use `recurse=True` to automatically convert nested dictionaries into UltraDict instances, enabling seamless nested updates across processes. ```python from UltraDict import UltraDict # Create recursive UltraDict (nested dicts become UltraDict instances) ultra = UltraDict(name='nested-example', recurse=True) # Add nested structure - inner dict is automatically converted ultra['config'] = { 'database': { 'host': 'localhost', 'port': 5432 }, 'cache': { 'enabled': True, 'ttl': 3600 } } # Verify nested dict is an UltraDict print(type(ultra['config'])) # Output: # From another process - connect and modify nested values other = UltraDict(name='nested-example') other['config']['database']['port'] = 5433 other['config']['cache']['ttl'] += 100 # Changes are reflected in original print(ultra['config']['database']['port']) # Output: 5433 print(ultra['config']['cache']['ttl']) # Output: 3700 ``` -------------------------------- ### Run Automated Performance Tests Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Executes the performance test suite located in the repository to compare operations per second. ```bash python ./tests/performance/performance.py Testing Performance with 1000000 operations each Redis (writes) = 24,351 ops per second Redis (reads) = 30,466 ops per second Python MPM dict (writes) = 19,371 ops per second Python MPM dict (reads) = 22,290 ops per second Python dict (writes) = 16,413,569 ops per second Python dict (reads) = 16,479,191 ops per second UltraDict (writes) = 479,860 ops per second UltraDict (reads) = 2,337,944 ops per second UltraDict (shared_lock=True) (writes) = 41,176 ops per second UltraDict (shared_lock=True) (reads) = 1,518,652 ops per second Ranking: writes: Python dict = 16,413,569 (factor 1.0) UltraDict = 479,860 (factor 34.2) UltraDict (shared_lock=True) = 41,176 (factor 398.62) Redis = 24,351 (factor 674.04) Python MPM dict = 19,371 (factor 847.33) reads: Python dict = 16,479,191 (factor 1.0) UltraDict = 2,337,944 (factor 7.05) UltraDict (shared_lock=True) = 1,518,652 (factor 10.85) Redis = 30,466 (factor 540.9) Python MPM dict = 22,290 (factor 739.31) ``` -------------------------------- ### UltraDict Exception Handling Source: https://context7.com/ronny-rentner/ultradict/llms.txt UltraDict provides specific exceptions for different error conditions. These include `AlreadyExists`, `CannotAttachSharedMemory`, `CannotAcquireLock`, `CannotAcquireLockTimeout`, `ParameterMismatch`, `AlreadyClosed`, and `FullDumpMemoryFull`. ```python from UltraDict import UltraDict # AlreadyExists - when create=True but memory exists try: UltraDict(name='existing', create=True) UltraDict(name='existing', create=True) # Raises except UltraDict.Exceptions.AlreadyExists as e: print(f"Memory already exists: {e}") # CannotAttachSharedMemory - when memory doesn't exist try: UltraDict(name='nonexistent', create=False) except UltraDict.Exceptions.CannotAttachSharedMemory as e: print(f"Cannot attach: {e}") # CannotAcquireLock - non-blocking acquire fails ultra = UltraDict(shared_lock=True) try: # Simulate another process holding lock ultra.lock.acquire(block=False) except UltraDict.Exceptions.CannotAcquireLock as e: print(f"Lock held by PID: {e.blocking_pid}") # CannotAcquireLockTimeout - timeout exceeded try: with ultra.lock(timeout=1.0): pass except UltraDict.Exceptions.CannotAcquireLockTimeout as e: print(f"Timeout waiting for lock held by PID: {e.blocking_pid}") # ParameterMismatch - inconsistent parameters between processes ultra1 = UltraDict(name='param-test', shared_lock=True) try: ultra2 = UltraDict(name='param-test', shared_lock=False) # Mismatch! except UltraDict.Exceptions.ParameterMismatch as e: print(f"Parameter mismatch: {e}") # AlreadyClosed - accessing closed UltraDict ultra = UltraDict() ultra.close() try: print(ultra['key']) except UltraDict.Exceptions.AlreadyClosed as e: print(f"Dict closed: {e}") # Can still access local cache: ultra.data # FullDumpMemoryFull - static full_dump_size too small try: ultra = UltraDict(full_dump_size=100) ultra['big_data'] = 'x' * 1000 # Too big for dump size except UltraDict.Exceptions.FullDumpMemoryFull as e: print(f"Full dump memory too small: {e}") ``` -------------------------------- ### UltraDict Status Overview Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Displays the current status of the UltraDict instance, including details about shared memory buffers, locks, and serialization settings. Keys ending with `_remote` indicate data stored in control shared memory accessible across processes. ```python {'buffer': SharedMemory('my-name_memory', size=100000), 'buffer_size': 100000, 'control': SharedMemory('my-name', size=1000), 'full_dump_counter': 1, 'full_dump_counter_remote': 1, 'full_dump_memory': SharedMemory('psm_765691cd', size=100057), 'full_dump_memory_name_remote': 'psm_765691cd', 'full_dump_size': None, 'full_dump_static_size_remote': , 'lock': , 'lock_pid_remote': 0, 'lock_remote': 0, 'name': 'my-name', 'recurse': False, 'recurse_remote': , 'serializer': , 'shared_lock_remote': , 'update_stream_position': 0, 'update_stream_position_remote': 0} ``` -------------------------------- ### Thread-Safe Operations with UltraDict Lock Source: https://context7.com/ronny-rentner/ultradict/llms.txt Demonstrates using the `lock` attribute for synchronizing compound operations, ensuring thread-safe access, especially when using `shared_lock=True` for spawn contexts. ```python from UltraDict import UltraDict import multiprocessing # Default RLock (fast, for forked processes) ultra = UltraDict(buffer_size=10_000) ultra['counter'] = 0 def worker_fork(d, iterations): for _ in range(iterations): with d.lock: d['counter'] += 1 # Atomic increment ``` -------------------------------- ### Load Latest Full Dump with UltraDict Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Loads the most recent full dump of the UltraDict state from persistent storage. This operation is automatically called when accessing the UltraDict, but can be explicitly invoked. ```python >>> # Load latest full dump if one is available >>> ultra.load() ``` -------------------------------- ### Measure Write Performance Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Uses timeit.repeat to compare write speeds across different dictionary implementations. ```python >>> min(timeit.repeat('orig[1] = 1', globals=globals())) # original 0.028232071083039045 >>> min(timeit.repeat('ultra[1] = 1', globals=globals())) # UltraDict 2.911152713932097 >>> min(timeit.repeat('managed[1] = 1', globals=globals())) # Manager 31.641707635018975 >>> min(timeit.repeat('r.set(1, 1)', globals=globals())) # Redis 124.3432381930761 ``` -------------------------------- ### Parallel Counter with Spawn Context Source: https://context7.com/ronny-rentner/ultradict/llms.txt Uses shared_lock=True to ensure compatibility with spawn-based multiprocessing, such as on Windows. ```python from UltraDict import UltraDict import multiprocessing count = 100_000 def increment_counter(name, target): """Worker that connects by name and increments counter""" d = UltraDict(name=name, shared_lock=True) for _ in range(target): with d.lock: d['counter'] += 1 if __name__ == '__main__': # Create with shared_lock and static full_dump_size for Windows ultra = UltraDict( buffer_size=10_000, shared_lock=True, full_dump_size=10_000 ) ultra['counter'] = 0 ctx = multiprocessing.get_context('spawn') processes = [ ctx.Process(target=increment_counter, args=[ultra.name, count // 4]) for _ in range(4) ] for p in processes: p.start() for p in processes: p.join() print(f"Counter: {ultra['counter']} == {count}") # Output: Counter: 100000 == 100000 ``` -------------------------------- ### Implement Lock Timeouts and Stealing Source: https://context7.com/ronny-rentner/ultradict/llms.txt Uses a timeout and steal_after_timeout to recover from potential deadlocks or crashed processes holding the lock. ```python # Lock with timeout and steal after timeout (for crash recovery) def worker_with_timeout(name, iterations): d = UltraDict(name=name, shared_lock=True) for _ in range(iterations): with d.lock(timeout=5.0, steal_after_timeout=True): d['counter'] += 1 ``` -------------------------------- ### Parallel Counter with Fork Context Source: https://context7.com/ronny-rentner/ultradict/llms.txt Uses the default RLock for faster performance in fork-based multiprocessing environments. ```python from UltraDict import UltraDict import multiprocessing count = 100_000 def increment_counter(d, target): """Worker function that increments counter""" for _ in range(target): with d.lock: d['counter'] += 1 if __name__ == '__main__': # Create UltraDict with RLock (default, fast for fork) ultra = UltraDict(buffer_size=10_000) ultra['counter'] = 0 # Create two worker processes p1 = multiprocessing.Process(target=increment_counter, args=[ultra, count // 2]) p2 = multiprocessing.Process(target=increment_counter, args=[ultra, count // 2]) p1.start() p2.start() p1.join() p2.join() print(f"Counter: {ultra['counter']} == {count}") # Output: Counter: 100000 == 100000 ``` -------------------------------- ### Measure Read Performance Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Uses the timeit module to compare read speeds across different dictionary implementations. ```python >>> timeit.timeit('orig[1]', globals=globals()) # original 0.03832335816696286 >>> timeit.timeit('ultra[1]', globals=globals()) # UltraDict 0.5248982920311391 >>> timeit.timeit('managed[1]', globals=globals()) # Manager 40.85506196087226 >>> timeit.timeit('r.get(1)', globals=globals()) # Redis 49.3497632863 >>> timeit.timeit('ultra.data[1]', globals=globals()) # UltraDict data cache 0.04309639008715749 ``` -------------------------------- ### Perform Non-blocking Lock Attempts Source: https://context7.com/ronny-rentner/ultradict/llms.txt Attempts to acquire a lock without blocking, handling the CannotAcquireLock exception to identify the blocking process. ```python # Non-blocking lock attempt def try_lock(d): try: result = d.lock.acquire(block=False) if result: d['value'] = 'updated' d.lock.release() return True except UltraDict.Exceptions.CannotAcquireLock as e: print(f'Lock held by PID {e.blocking_pid}') return False ``` -------------------------------- ### Access Nested Recursive UltraDict in Python Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Access and modify nested UltraDict instances. Changes to nested counters are synchronized across processes. ```python from UltraDict import UltraDict other = UltraDict(name='psm_0a2713e4') other['nested']['counter'] += 1 ``` -------------------------------- ### Explicitly Unlinking UltraDict Shared Memory Buffers Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Provides a method to manually clean up shared memory buffers used by UltraDict by their name. This is useful for explicit cleanup, especially if a program crashes without proper unlinking. ```python # Unlink both shared memory buffers possibly used by UltraDict name = 'my-dict-name' UltraDict.unlink_by_name(name, ignore_errors=True) UltraDict.unlink_by_name(f'{name}_memory', ignore_errors=True) ``` -------------------------------- ### Recovering from Stale Locks Source: https://context7.com/ronny-rentner/ultradict/llms.txt Handle situations where a process crashes while holding a lock. Use `timeout` and `steal_after_timeout` parameters to recover automatically. The `CannotAcquireLockTimeout` exception is raised if the lock cannot be acquired within the specified timeout. ```python from UltraDict import UltraDict import multiprocessing import time stale_lock_timeout = 5.0 # Max time any process should hold lock def robust_worker(name, target): """Worker with stale lock recovery""" d = UltraDict(name=name, shared_lock=True) while d['counter'] < target: try: # Timeout + steal allows recovery from crashed processes with d.lock(timeout=stale_lock_timeout, steal_after_timeout=True): if d['counter'] < target: d['counter'] += 1 # Simulate work time.sleep(0.001) except UltraDict.Exceptions.CannotAcquireLockTimeout: print(f"Lock timeout, will retry and potentially steal") continue if __name__ == '__main__': ultra = UltraDict(buffer_size=10_000, shared_lock=True) ultra['counter'] = 0 ctx = multiprocessing.get_context('spawn') workers = [ ctx.Process(target=robust_worker, args=[ultra.name, 100]) for _ in range(3) ] for w in workers: w.start() for w in workers: w.join() print(f"Final counter: {ultra['counter']}") ``` -------------------------------- ### Access Underlying Local Dictionary Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Provides direct access to the underlying local dictionary for maximum performance. Use this when high-speed read operations are critical and shared memory overhead is not desired. ```python >>> # Access underlying local dict directly for maximum performance >>> ultra.data ``` -------------------------------- ### Close UltraDict Connection Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Closes the connection to the shared memory used by UltraDict. This operation returns the data as a standard Python dictionary and releases resources associated with the shared memory. ```python >>> # Close connection to shared memory; will return the data as a dict >>> ultra.close() ``` -------------------------------- ### Unlink Shared Memory Source: https://context7.com/ronny-rentner/ultradict/llms.txt Unlink shared memory by instance or by name. This makes the memory inaccessible to new processes. Manual cleanup on Linux involves deleting files in /dev/shm/. ```python ultra2 = UltraDict(name='to-remove') ultra2.unlink() # Removes shared memory ``` ```python name = 'crashed-dict' UltraDict.unlink_by_name(name, ignore_errors=True) UltraDict.unlink_by_name(f'{name}_memory', ignore_errors=True) ``` -------------------------------- ### Unlink UltraDict Shared Memory Source: https://github.com/ronny-rentner/ultradict/blob/main/readme.md Unlinks all shared memory segments associated with the UltraDict instance. After unlinking, the shared memory will no longer be visible or accessible to new processes. ```python >>> # Unlink all shared memory, it will not be visible to new processes afterwards >>> ultra.unlink() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.