Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0984c42

Browse filesBrowse files
committed
Sender now has a closed state and won't emit
fixes #110
1 parent c87641e commit 0984c42
Copy full SHA for 0984c42

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎fluent/sender.py

Copy file name to clipboardExpand all lines: fluent/sender.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self,
7373
self.socket = None
7474
self.pendings = None
7575
self.lock = threading.Lock()
76+
self._closed = False
7677
self._last_error_threadlocal = threading.local()
7778

7879
def emit(self, label, data):
@@ -109,6 +110,9 @@ def clear_last_error(self, _thread_id=None):
109110

110111
def close(self):
111112
with self.lock:
113+
if self._closed:
114+
return
115+
self._closed = True
112116
if self.pendings:
113117
try:
114118
self._send_data(self.pendings)
@@ -130,6 +134,8 @@ def _make_packet(self, label, timestamp, data):
130134

131135
def _send(self, bytes_):
132136
with self.lock:
137+
if self._closed:
138+
return False
133139
return self._send_internal(bytes_)
134140

135141
def _send_internal(self, bytes_):

‎tests/test_sender.py

Copy file name to clipboardExpand all lines: tests/test_sender.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ def test_emit_error(self):
146146
self.assertEqual(len(data), 1)
147147
self.assertEqual(data[0][2]["message"], "Can't output to log")
148148

149+
def test_emit_after_close(self):
150+
with self._sender as sender:
151+
self.assertTrue(sender.emit("blah", {"a": "123"}))
152+
sender.close()
153+
self.assertFalse(sender.emit("blah", {"a": "456"}))
154+
155+
data = self._server.get_received()
156+
self.assertEqual(len(data), 1)
157+
self.assertEqual(data[0][2]["a"], "123")
158+
149159
def test_verbose(self):
150160
with self._sender as sender:
151161
sender.verbose = True

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.