Closed AlyaGomaa closed 1 month ago
same goes with all the usage of timerthread in ssh.py and dns.py
Here's a plan of how this async hell is going to be implemented
import asyncio
import warnings, time
warnings.filterwarnings("ignore", category=RuntimeWarning)
class X: def init(self): self.tasks = []
async def check_dns(self):
"""any function that waits for anything will look lik ethis"""
print("Fetching data...")
await asyncio.sleep(2)
print("Data fetched!")
async def analyze(self):
"""Analyze of any flowanalyzer in flowalerts, like dns.py ssh.py etc"""
print("analyze just started")
time.sleep(3)
t = asyncio.create_task(self.check_dns())
self.tasks.append(t)
print("Analyze just ended")
async def shutdown_gracefully(self):
await asyncio.gather(*self.tasks)
print("shutdown gracefully is done")
def main(self):
"""main of flowalerts supposedly"""
loop = asyncio.get_event_loop()
loop.create_task(self.analyze())
print("flowalerts main is done execution")
def controller(self):
"""will be IModule's run """
loop = asyncio.get_event_loop()
self.main() # Schedule tasks
loop.run_until_complete(self.shutdown_gracefully())
X().controller()
done here #1012
See if this works
the goal is to avoid starting threads as much as possible to avoid hanging threads/processes in memory