Skip to content

Commit c7f2e3b

Browse files
authored
Merge pull request #1092 from stratosphereips/alya/fix_the_starting_of_abstract_class
remove duplicate AsyncModule class from module.py
2 parents 1feaa36 + e7207e6 commit c7f2e3b

File tree

3 files changed

+6
-73
lines changed

3 files changed

+6
-73
lines changed

modules/ip_info/ip_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from slips_files.common.flow_classifier import FlowClassifier
2121
from slips_files.core.helpers.whitelist.whitelist import Whitelist
2222
from .asn_info import ASN
23-
from slips_files.common.abstracts.module import AsyncModule
23+
from slips_files.common.abstracts.async_module import AsyncModule
2424
from slips_files.common.slips_utils import utils
2525
from slips_files.core.structures.evidence import (
2626
Evidence,

slips_files/common/abstracts/async_module.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ async def shutdown_gracefully(self):
2424
async def run_main(self):
2525
return await self.main()
2626

27-
def run_async_function(self, func: Callable):
27+
@staticmethod
28+
def run_async_function(func: Callable):
2829
loop = asyncio.get_event_loop()
2930
return loop.run_until_complete(func())
3031

@@ -44,7 +45,6 @@ def run(self):
4445
self.print_traceback()
4546
return
4647

47-
keyboard_int_ctr = 0
4848
while True:
4949
try:
5050
if self.should_stop():
@@ -59,10 +59,10 @@ def run(self):
5959
return
6060

6161
except KeyboardInterrupt:
62-
keyboard_int_ctr += 1
63-
if keyboard_int_ctr >= 2:
62+
self.keyboard_int_ctr += 1
63+
if self.keyboard_int_ctr >= 2:
6464
# on the second ctrl+c Slips immediately stop
65-
return
65+
return True
6666
# on the first ctrl + C keep looping until the should_stop()
6767
# returns true
6868
continue

slips_files/common/abstracts/module.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import asyncio
21
import sys
32
import traceback
43
import warnings
@@ -7,7 +6,6 @@
76
from typing import (
87
Dict,
98
Optional,
10-
Callable,
119
)
1210
from slips_files.common.printer import Printer
1311
from slips_files.core.output import Output
@@ -180,68 +178,3 @@ def run(self):
180178
except Exception:
181179
self.print_traceback()
182180
return
183-
184-
185-
class AsyncModule(IModule, ABC, Process):
186-
"""
187-
An abstract class for asynchronous slips modules
188-
"""
189-
190-
name = "abstract class"
191-
192-
def __init__(self, *args, **kwargs):
193-
IModule.__init__(self, *args, **kwargs)
194-
195-
def init(self, **kwargs): ...
196-
197-
async def main(self): ...
198-
199-
async def shutdown_gracefully(self):
200-
"""Implement the async shutdown logic here"""
201-
pass
202-
203-
async def run_main(self):
204-
return await self.main()
205-
206-
@staticmethod
207-
def run_async_function(func: Callable):
208-
loop = asyncio.get_event_loop()
209-
return loop.run_until_complete(func())
210-
211-
def run(self):
212-
try:
213-
error: bool = self.pre_main()
214-
if error or self.should_stop():
215-
self.run_async_function(self.shutdown_gracefully)
216-
return
217-
except KeyboardInterrupt:
218-
self.run_async_function(self.shutdown_gracefully)
219-
return
220-
except Exception:
221-
self.print_traceback()
222-
return
223-
224-
while True:
225-
try:
226-
if self.should_stop():
227-
self.run_async_function(self.shutdown_gracefully)
228-
return
229-
230-
# if a module's main() returns 1, it means there's an
231-
# error and it needs to stop immediately
232-
error: bool = self.run_async_function(self.run_main)
233-
if error:
234-
self.run_async_function(self.shutdown_gracefully)
235-
return
236-
237-
except KeyboardInterrupt:
238-
self.keyboard_int_ctr += 1
239-
if self.keyboard_int_ctr >= 2:
240-
# on the second ctrl+c Slips immediately stop
241-
return True
242-
# on the first ctrl + C keep looping until the should_stop()
243-
# returns true
244-
continue
245-
except Exception:
246-
self.print_traceback()
247-
return

0 commit comments

Comments
 (0)