Skip to content
Snippets Groups Projects
Commit 4a380971 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Termination option added

parent b7393922
No related branches found
Tags v2.14.16
No related merge requests found
......@@ -4,8 +4,9 @@ from Queue import Queue, Empty
from satella.network.socket import BaseSocket
from satella.network.exceptions import ConnectionFailedException
from satella.threads import BaseThread
class SelectLoop(Thread):
class SelectLoop(BaseThread):
"""
Thread that does a select loop.
In general, you are expected to subclass it and write methods corresponding to tasks. The loop works like this:
......@@ -113,7 +114,7 @@ class SelectLoop(Thread):
def run(self):
self.on_startup()
while True:
while not self._terminating:
self.loop()
self.on_cleanup()
for sock in self.client_sockets: # Close surviving client sockets
......
class BaseThread(Thread):
"""Thread with internal termination flag"""
def __init__(self, *args, **kwargs):
self._terminating = False
Thread.__init__(self, *args, **kwargs)
def terminate(self):
"""Sets internal termination flag"""
self._terminating = True
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment