You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Some attack recipes are extremely slow, so a timeout mechanism for a single attack on one sample is needed.
Describe the solution you'd like
Use a timeout context manager like
@contextmanagerdeftimeout(duration: float):
""" A context manager that raises a `TimeoutError` after a specified time. Parameters ---------- duration: float, the time duration in seconds, should be non-negative, 0 for no timeout References ---------- https://stackoverflow.com/questions/492519/timeout-on-a-function-call """ifnp.isinf(duration):
duration=0elifduration<0:
raiseValueError("duration must be non-negative")
elifduration>0: # granularity is 1 second, so round upduration=max(1, int(duration))
deftimeout_handler(signum, frame):
raiseTimeoutError(f"block timedout after {duration} seconds")
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(duration)
yieldsignal.alarm(0)
I think this is a great idea @wenh06. The attack search process is exponential in nature so it's easy to get into a state where the attack will never finish in a reasonable amount of time. It could also be nice to try and predict how long the attack would take, and warn the user if they're running something that is very very slow.
There are lots of ways to make functions time out in Python. Maybe asyncio is nicest, but it might cause problems – like weird error messages when things break – if all the important code is running asynchronously.
We should probably add a new type of attack result, like TimedOutAttackResult or ExpiredAttackResult or something like that, and show it in the results (X skipped, Y succeeded, Z failed, and M timed out) if users specify a timeout.
Alternatively maybe we could just consider a timeout a failure (this is what query budget does) but that could be confusing, since it wouldn't be clear how something failed. (Though maybe it's confusing for query budget too..)
Bump on this! I really like this, and have had to implement a custom timeout feature in my own production code, so this would definitely be really useful. The issue is that most attacks finish in just a couple minutes, but some small proportion of attacks take more than 2 days to finish, so having a timeout mechanism allows us to finish most of our attacks in a reasonable amount of time
Is your feature request related to a problem? Please describe.
Some attack recipes are extremely slow, so a timeout mechanism for a single attack on one sample is needed.
Describe the solution you'd like
Use a timeout context manager like
and replace this line
with, for example,
One can also add a
time-out
argument incommands.textattack_cli
, and pass this argument in related classes and functions.Describe alternatives you've considered
NA
Additional context
NA
The text was updated successfully, but these errors were encountered: