1

I am calling a function named as func for each sentence in my corpus as follows in python.

count =0    
for sentence in sentences:
   count += 1
   results.append(func(sentence))

I want to pass the sentences that takes too long to process by using timeout (e.g., timeout after 30 seconds and print the sentence number).

I tried to use the solution mentioned in: Timeout on a function call and timeout-decorator library as well.

However, both of the solutions returned me the same error mentioned below.

signal.signal(signal.SIGALRM, handler)

AttributeError: module 'signal' has no attribute 'SIGALRM'

Is there a way to perform timeout in python 3? Please let me know if further details are needed.

EmJ
  • 3,959
  • 2
  • 20
  • 68
  • Possible duplicate of [Postpone code for later execution in python (like setTimeout in javascript)](https://stackoverflow.com/questions/10154568/postpone-code-for-later-execution-in-python-like-settimeout-in-javascript) – Derte Trdelnik Jan 11 '19 at 13:19

1 Answers1

1

The signal package is part of UNIX/Linux package and needs to be installed. If you are on windows check this out https://github.com/Unity-Technologies/ml-agents/issues/7

pkrulz
  • 48
  • 6
  • If it answered your question, can you please click the tick mark on the left side and accept it as answer – pkrulz Jan 12 '19 at 03:05
  • 1
    If you are on windows this might help. https://stackoverflow.com/questions/8420422/python-windows-equivalent-of-sigalrm – pkrulz Jan 12 '19 at 03:08