Changing property of prim through python code

I am trying to change ‘xformOp:translate’ property of a prim using python extension. When I enable the extension everything works fine, stage gets loaded successful, expected translation of prim also gets completed by reading attribute values from a json file.
I am using one more python script which includes watchdog package to detect any changes in the json file and once it triggers an event, prim is expected to translate.
So, if values in the json file are changed sometimes it completes translation of prim and if we keep changing json file, the Omniverse platform goes into ‘not responding’ state.
It is completely random.
It gives the error as ‘RuntimeError’> There is no current event loop in thread ‘Thread-5’.

i am personally not familiar with that workflow of changing parameter through json (and the watchdog package), so i would defer to what the mods/devs have to recommend.

where are you getting that error from? in OV? if so, maybe try uploading your log; maybe there are some additional context that could help explain the messages you are getting.

Could you provide the snippet of code that you are using?

from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler
import json
from pxr import UsdGeom
import os

os.chdir(os.path.dirname(os.path.abspath(__file__)))

class PathPointGenerator(PatternMatchingEventHandler):
    # Inititate pattern matching handler.
    def __init__(self):
        PatternMatchingEventHandler.__init__(self, patterns=["*_input.json"])

    # Function to detect changes in files
    def on_modified(self, event):
        print(f"Watchdog received {event} event")
        # Read detected file information
        filepath = event.src_path
        # open the input file
        with open(filepath, "r") as input_file:
            input_data = json.load(input_file)
        x = input_data["coordinates"]["X"]
        y = input_data["coordinates"]["Y"]
        z = input_data["coordinates"]["Z"]

        stage = omni.usd.get_context().get_stage()
        pathName = "/World/Cube"
        cubeGeom = stage.GetPrimAtPath(pathName)
        UsdGeom.XformCommonAPI(cubeGeom).SetTranslate((x, y, z))

watch_path = "../../../data"
event_handler = PathPointGenerator()
observer = Observer()
observer.schedule(event_handler, watch_path, recursive=False)
observer.start()

The above code snippet is different than extension.py file. This python script is at the same repository as extension.py.

This script also runs as soon as I enable extension in Omniverse platform.

Instead of UsdGeom could you try cubeGeom.GetAttribute('xformOp:translate').Set((x,y,z))

I tried your suggestion, but still, the Omniverse platform freezes.

Currently, I am using the watchdog package to monitor a JSON file for changes in the coordinates and this file is stored in the data folder of the extension.

Is there any other way in Omniverse itself to monitor a file in real time for changes and reflect the changes on the Omniverse platform?