Created
August 13, 2024 03:42
-
-
Save madhavajay/3aec46de3ee42232b0c7bc7f28959830 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
import threading | |
import random | |
import string | |
from typing import Any | |
from dataclasses import dataclass | |
@dataclass | |
class Pointer: | |
syft_id: int | |
value: Any | |
import inspect | |
class RemoteClient: | |
def get_pointer(self): | |
return Pointer(syft_id=int(random.random() * 10), value="a") | |
def live_update(self, interval=3): | |
frame = inspect.currentframe().f_back | |
local_vars = frame.f_locals | |
def modify_variable(): | |
for var_name, var_value in local_vars.items(): | |
if hasattr(var_value, "syft_id"): | |
random_letter = random.choice(string.ascii_letters) | |
var_value.value = random_letter | |
print("syft obj", var_name, var_value) | |
threading.Timer(interval, modify_variable).start() | |
modify_variable() | |
client = RemoteClient() | |
a = client.get_pointer() | |
print(a) | |
b = client.get_pointer() | |
print(b) | |
c = client.get_pointer() | |
print(c) | |
# Run the method on a timer | |
client.live_update() | |
print(a, b, c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment