|
7 | 7 | Date: June 11, 2023 |
8 | 8 | For more information see https://github.com/jasonacox/tinytuya |
9 | 9 |
|
| 10 | +Requirements: |
| 11 | + pip install psutil tinytuya colorama requests |
| 12 | +
|
10 | 13 | Description |
11 | 14 | Server continually listens for Tuya UDP discovery packets and updates the database of devices |
12 | 15 | and uses devices.json to determine metadata about devices. |
|
43 | 46 | print("WARN: Unable to import requests library, Cloud functions will not work.") |
44 | 47 | print("WARN: Check dependencies. See https://github.com/jasonacox/tinytuya/issues/377") |
45 | 48 | print("WARN: Error: {}.".format(impErr.args[0])) |
46 | | -import resource |
| 49 | + |
| 50 | +# Memory usage reporting uses the 'psutil' library, which is cross-platform. |
| 51 | +# If 'psutil' is not available, memory stats will be set to None. |
| 52 | +try: |
| 53 | + import psutil |
| 54 | + HAS_PSUTIL = True |
| 55 | +except ImportError: |
| 56 | + HAS_PSUTIL = False |
47 | 57 | import signal |
48 | 58 | import sys |
49 | 59 | import os |
|
62 | 72 | import tinytuya |
63 | 73 | from tinytuya import scanner |
64 | 74 |
|
65 | | -BUILD = "p14" |
| 75 | +BUILD = "p15" |
66 | 76 |
|
67 | 77 | # Defaults from Environment |
68 | 78 | APIPORT = int(os.getenv("APIPORT", "8888")) |
@@ -426,7 +436,12 @@ def do_GET(self): |
426 | 436 | elif self.path == '/stats': |
427 | 437 | # Give Internal Stats |
428 | 438 | serverstats['ts'] = int(time.time()) |
429 | | - serverstats['mem'] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
| 439 | + # Report memory usage using psutil if available (cross-platform) |
| 440 | + if HAS_PSUTIL: |
| 441 | + process = psutil.Process(os.getpid()) |
| 442 | + serverstats['mem'] = process.memory_info().rss // 1024 # Resident Set Size in KB |
| 443 | + else: |
| 444 | + serverstats['mem'] = None # psutil not available |
430 | 445 | serverstats['cloudcreds'] = cloudcreds |
431 | 446 | serverstats['cloudsync'] = cloudsync |
432 | 447 | serverstats['cloudsyncdone'] = cloudsyncdone |
|
0 commit comments