metadata

Check-in [5d912ee6bc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Handle network errors w. cleanup
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:5d912ee6bc483ab4711d1c45db981e3e887ea9641d7deb8bc5a94c11f204194e
User & Date: vashon 2018-06-18 22:31:37
Context
2018-06-18
22:40
Idle shutdown of stream monitoring check-in: 8a1cc96ebf user: vashon tags: trunk
22:31
Handle network errors w. cleanup check-in: 5d912ee6bc user: vashon tags: trunk
22:23
Initial run check-in: d4b4a6924b user: vashon tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to stream.py.

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
...
171
172
173
174
175
176
177


178
179
180



















181
182
183
184
185
186
187
...
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

    # Pull from a stream with Icecast metadata.
    # Because Icecast metadata is kind of a hairball of legacy and
    #  modern, we just talk TCP to it ourselves.
    # This function only returns on errors like aborted streams.
    # On idle timeout, it simply exits after clearing itself
    #  from the stream state.
    def watch(self, gen):
	gen = gen or 0

	# Request it
	s.send("GET %s?gen=%d HTTP/1.0\r\n%s\r\n" %
	    (self.path, gen, Args))

	# Assemble the HTTP response headers.  We'll likely have
	#  more than that, which will be passed down to the loop
	#  below.
	res = ""
	headers = {}
	hdone = False
................................................................................
		res[k] = v
	    
	    if not res:
		sys.stderr.write("%s no usable metadata\n" % (self.host,))
		continue

	    # Convert to a JSON string


	    self.gen += 1
	    self.json = json.dumps(res)
	    self.wakeups()




















    # We're running on a thread for a given HTTP request.
    # Send back metadata, now, or in the future when it
    #  changes (long polling)
    def serve(self, req, gen):

	# If we already have the answer they want, send it back
................................................................................
	#  perhaps started up a service thread
	s = threading.Semaphore(0)
	self.queue.append(s)

	# Start a thread if needed
	if self.thread is None:
	    self.thread = t = \
		threading.Thread(target=self.watch, args=(gen,))
	    t.start()

	# Wait for the thread to find metadata and wake us up
	s.acquire()

	# We're back, send the contents
	assert self.json
	return True,req.send_result(self.json, "application/json")







|
<


|
|







 







>
>



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|








67
68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227

    # Pull from a stream with Icecast metadata.
    # Because Icecast metadata is kind of a hairball of legacy and
    #  modern, we just talk TCP to it ourselves.
    # This function only returns on errors like aborted streams.
    # On idle timeout, it simply exits after clearing itself
    #  from the stream state.
    def watch(self):


	# Request it
	s.send("GET %s HTTP/1.0\r\n%s\r\n" %
	    (self.path, Args))

	# Assemble the HTTP response headers.  We'll likely have
	#  more than that, which will be passed down to the loop
	#  below.
	res = ""
	headers = {}
	hdone = False
................................................................................
		res[k] = v
	    
	    if not res:
		sys.stderr.write("%s no usable metadata\n" % (self.host,))
		continue

	    # Convert to a JSON string
	    res["err"] = None
	    res["gen"] = self.gen
	    self.gen += 1
	    self.json = json.dumps(res)
	    self.wakeups()

    # Our main worker is self.watch(), right above.  This wraps it,
    #  so that it can return here on network failure, and we can
    #  tear down this thread.
    def run_watch(self):
	try:
	    self.watch()
	except:
	    pass
	self.thread = None

	# Kick free any pending waiters
	res = {"gen": self.gen, "err": "closed"}
	self.gen += 1
	self.json = json.dumps(res)
	self.wakeups()

	# Bye-bye
	sys.exit(0)

    # We're running on a thread for a given HTTP request.
    # Send back metadata, now, or in the future when it
    #  changes (long polling)
    def serve(self, req, gen):

	# If we already have the answer they want, send it back
................................................................................
	#  perhaps started up a service thread
	s = threading.Semaphore(0)
	self.queue.append(s)

	# Start a thread if needed
	if self.thread is None:
	    self.thread = t = \
		threading.Thread(target=self.run_watch)
	    t.start()

	# Wait for the thread to find metadata and wake us up
	s.acquire()

	# We're back, send the contents
	assert self.json
	return True,req.send_result(self.json, "application/json")