2003-07-04 14:24:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2014-02-28 23:12:34 +00:00
|
|
|
# Copyright (C) 2000-2014 Bastian Kleineidam
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-01-19 15:08:02 +00:00
|
|
|
"""
|
2005-03-04 23:18:10 +00:00
|
|
|
Support for managing threads.
|
2005-01-19 15:08:02 +00:00
|
|
|
"""
|
2006-05-24 22:29:22 +00:00
|
|
|
import threading
|
2005-03-04 23:18:10 +00:00
|
|
|
|
2006-05-24 22:29:22 +00:00
|
|
|
|
|
|
|
|
class StoppableThread (threading.Thread):
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Thread class with a stop() method. The thread itself has to check
|
|
|
|
|
regularly for the stopped() condition."""
|
2006-05-24 22:29:22 +00:00
|
|
|
|
|
|
|
|
def __init__ (self):
|
2011-02-17 06:38:02 +00:00
|
|
|
"""Store stop event."""
|
2006-05-24 22:29:22 +00:00
|
|
|
super(StoppableThread, self).__init__()
|
|
|
|
|
self._stop = threading.Event()
|
|
|
|
|
|
|
|
|
|
def stop (self):
|
2011-02-17 06:38:02 +00:00
|
|
|
"""Set stop event."""
|
2006-05-24 22:29:22 +00:00
|
|
|
self._stop.set()
|
|
|
|
|
|
2011-02-18 13:49:53 +00:00
|
|
|
def stopped (self, timeout=None):
|
2011-02-17 06:38:02 +00:00
|
|
|
"""Return True if stop event is set."""
|
2012-01-04 19:17:53 +00:00
|
|
|
return self._stop.wait(timeout)
|