Prechádzať zdrojové kódy

fix(sdk): python source sample should not end (#1099)

Source

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
ngjaying 3 rokov pred
rodič
commit
868819cdaf
1 zmenil súbory, kde vykonal 4 pridanie a 2 odobranie
  1. 4 2
      sdk/python/example/pysam/pyjson.py

+ 4 - 2
sdk/python/example/pysam/pyjson.py

@@ -32,6 +32,7 @@ from ekuiper import Source, Context
 class PyJson(Source):
 class PyJson(Source):
     def __init__(self):
     def __init__(self):
         self.data = {"name": "pyjson", "value": 2021}
         self.data = {"name": "pyjson", "value": 2021}
+        self.running = True
 
 
     def configure(self, datasource: str, conf: dict):
     def configure(self, datasource: str, conf: dict):
         logging.info("configuring with datasource {} and conf {}".format(datasource, conf))
         logging.info("configuring with datasource {} and conf {}".format(datasource, conf))
@@ -39,10 +40,11 @@ class PyJson(Source):
     # noinspection PyTypeChecker
     # noinspection PyTypeChecker
     def open(self, ctx: Context):
     def open(self, ctx: Context):
         print("opening")
         print("opening")
-        for i in range(100):
+        while self.running:
             ctx.emit(self.data, None)
             ctx.emit(self.data, None)
-            print("emit")
             time.sleep(0.2)
             time.sleep(0.2)
+        print("closed")
 
 
     def close(self, ctx: Context):
     def close(self, ctx: Context):
         print("closing")
         print("closing")
+        self.running = False