mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-05 18:11:41 +00:00
19 lines
443 B
Python
19 lines
443 B
Python
import simplejson
|
|
|
|
|
|
def safe_json_dumps(obj):
|
|
"""Safe version of json.dumps that also converts objects to dicts so they can be output, and ignores NaN floats
|
|
which are invalid in JSON."""
|
|
|
|
return simplejson.dumps(obj, ensure_ascii=False, ignore_nan=True, default=lambda o: o.__dict__)
|
|
|
|
|
|
def empty_queue(q):
|
|
"""Empty a queue"""
|
|
|
|
while not q.empty():
|
|
try:
|
|
q.get_nowait()
|
|
except:
|
|
break
|