Duibonduil commited on
Commit
f04f971
·
verified ·
1 Parent(s): bf4ab00

Upload __init__.py

Browse files
Files changed (1) hide show
  1. aworld/trace/__init__.py +55 -0
aworld/trace/__init__.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding: utf-8
2
+ # Copyright (c) 2025 inclusionAI.
3
+ import threading
4
+ from .routes import setup_routes
5
+ from aworld.logs.util import logger
6
+
7
+ GLOBAL_TRACE_SERVER = None
8
+
9
+
10
+ class TraceServer:
11
+ def __init__(self, storage, port: int = 7079):
12
+ self._storage = storage
13
+ self._port = port
14
+ self._thread = None
15
+ self.app = None
16
+ self._started = False
17
+
18
+ def start(self):
19
+ self._thread = threading.Thread(target=self._start_app, daemon=True)
20
+ self._thread.start()
21
+ self._started = True
22
+
23
+ def join(self):
24
+ if self._thread:
25
+ self._thread.join()
26
+ else:
27
+ raise Exception("Trace server not started.")
28
+
29
+ def get_storage(self):
30
+ return self._storage
31
+
32
+ def is_started(self):
33
+ return self._started
34
+
35
+ def _start_app(self):
36
+ app = setup_routes(self._storage)
37
+ self.app = app
38
+ app.run(port=self._port)
39
+
40
+
41
+ def set_trace_server(storage, port: int = 7079, start_server=False):
42
+ global GLOBAL_TRACE_SERVER
43
+ if GLOBAL_TRACE_SERVER is None:
44
+ GLOBAL_TRACE_SERVER = TraceServer(storage, port)
45
+ if GLOBAL_TRACE_SERVER.is_started():
46
+ setup_routes(storage)
47
+ return
48
+ if start_server:
49
+ GLOBAL_TRACE_SERVER.start()
50
+
51
+
52
+ def get_trace_server():
53
+ if GLOBAL_TRACE_SERVER is None:
54
+ logger.warning("No trace server has been set.")
55
+ return GLOBAL_TRACE_SERVER