3

Is there a OS-independent or Windows-specific way to stop a regex search after a given amount of time or on user request?

My program provides text editing functionality with regex searching. If a user enters a pathological regex pattern searching may need too much time. It would be good to stop the search at user request or at least after a given timeout.

I found solutions for Linux/Unix using signal.alarm() but this function isn't supported on Windows.

Michael Butscher
  • 10,028
  • 4
  • 24
  • 25

1 Answers1

0

Just off the top of my head, do the search on a separate thread, if the time expires or cancelled, terminate the thread?

Robert McKee
  • 21,305
  • 1
  • 43
  • 57
  • I think the GIL prevents the monitor thread from getting a chance to stop the search thread while the search is running. – user2357112 Aug 14 '13 at 22:03
  • According to http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python it is unsafe and officially unsupported to terminate a thread – Michael Butscher Aug 14 '13 at 22:04
  • @user2357112 Good thing I don't really program in python, although IronPython doesn't have a GIL to cause such issues. – Robert McKee Aug 14 '13 at 22:18