Allow threads to be stopped externally
This commit is contained in:
parent
46b544fac6
commit
15afa90157
1 changed files with 10 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
import re
|
import re
|
||||||
import enum
|
import enum
|
||||||
import socket
|
import socket
|
||||||
|
import threading
|
||||||
import datetime
|
import datetime
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -38,7 +39,7 @@ class Session(Connection):
|
||||||
self.server = server
|
self.server = server
|
||||||
self.db: Database = server.connect_to_db()
|
self.db: Database = server.connect_to_db()
|
||||||
self.mode: SessionMode = SessionMode.READER
|
self.mode: SessionMode = SessionMode.READER
|
||||||
self.active: bool = True
|
self.stop: threading.Event = threading.Event()
|
||||||
|
|
||||||
self.newsgroup: Optional[Newsgroup] = None
|
self.newsgroup: Optional[Newsgroup] = None
|
||||||
self.user: Optional[User] = None
|
self.user: Optional[User] = None
|
||||||
|
@ -767,7 +768,7 @@ class Session(Connection):
|
||||||
line = self.readline()
|
line = self.readline()
|
||||||
|
|
||||||
if line == '':
|
if line == '':
|
||||||
self.active = False
|
if self.stop.is_set():
|
||||||
break
|
break
|
||||||
|
|
||||||
stripped = line.rstrip()
|
stripped = line.rstrip()
|
||||||
|
@ -799,7 +800,7 @@ class Session(Connection):
|
||||||
timestamp.strftime("%Y%m%d%H%M%S"))
|
timestamp.strftime("%Y%m%d%H%M%S"))
|
||||||
|
|
||||||
def _cmd_quit(self):
|
def _cmd_quit(self):
|
||||||
self.active = False
|
self.stop.set()
|
||||||
|
|
||||||
return self.respond(ResponseCode.NNTP_CONNECTION_CLOSING)
|
return self.respond(ResponseCode.NNTP_CONNECTION_CLOSING)
|
||||||
|
|
||||||
|
@ -835,7 +836,7 @@ class Session(Connection):
|
||||||
line = self.readline()
|
line = self.readline()
|
||||||
|
|
||||||
if line == '':
|
if line == '':
|
||||||
self.active = False
|
self.stop.set()
|
||||||
return
|
return
|
||||||
|
|
||||||
tokens = self.RE_SPLIT.split(line.rstrip())
|
tokens = self.RE_SPLIT.split(line.rstrip())
|
||||||
|
@ -858,7 +859,7 @@ class Session(Connection):
|
||||||
self.greet()
|
self.greet()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.active:
|
while not self.stop.is_set():
|
||||||
self.handle_command()
|
self.handle_command()
|
||||||
|
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue