mirror of https://github.com/ConsenSys/mythril
commit
9ae75a6a26
@ -1,25 +0,0 @@ |
||||
import signal |
||||
from types import FrameType |
||||
from mythril.exceptions import OutOfTimeError |
||||
|
||||
|
||||
def sigalrm_handler(signum: int, frame: FrameType) -> None: |
||||
raise OutOfTimeError |
||||
|
||||
|
||||
def start_timeout(timeout: int) -> None: |
||||
""" |
||||
Starts a timeout |
||||
:param timeout: Time in seconds to set the timeout for |
||||
:return: None |
||||
""" |
||||
signal.signal(signal.SIGALRM, sigalrm_handler) |
||||
signal.alarm(timeout) |
||||
|
||||
|
||||
def disable_timeout() -> None: |
||||
""" |
||||
Ensures that the timeout is disabled |
||||
:return: None |
||||
""" |
||||
signal.alarm(0) |
@ -0,0 +1,18 @@ |
||||
import time |
||||
from mythril.support.support_utils import Singleton |
||||
|
||||
|
||||
class TimeHandler(object, metaclass=Singleton): |
||||
def __init__(self): |
||||
self._start_time = None |
||||
self._execution_time = None |
||||
|
||||
def start_execution(self, execution_time): |
||||
self._start_time = int(time.time() * 1000) |
||||
self._execution_time = execution_time * 1000 |
||||
|
||||
def time_remaining(self): |
||||
return self._execution_time - (int(time.time() * 1000) - self._start_time) |
||||
|
||||
|
||||
time_handler = TimeHandler() |
@ -1 +1,21 @@ |
||||
"""This module contains utility functions for the Mythril support package.""" |
||||
|
||||
|
||||
class Singleton(type): |
||||
"""A metaclass type implementing the singleton pattern.""" |
||||
|
||||
_instances = {} |
||||
|
||||
def __call__(cls, *args, **kwargs): |
||||
"""Delegate the call to an existing resource or a a new one. |
||||
|
||||
This is not thread- or process-safe by default. It must be protected with |
||||
a lock. |
||||
|
||||
:param args: |
||||
:param kwargs: |
||||
:return: |
||||
""" |
||||
if cls not in cls._instances: |
||||
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) |
||||
return cls._instances[cls] |
||||
|
Loading…
Reference in new issue