how to send a json of yield list
dieter
dieter at handshake.de
Fri Oct 14 02:51:26 EDT 2016
meInvent bbird <jobmattcon at gmail.com> writes:
> after google a several solutions,
> First method i searched has memory error
> sock.send(json.dumps(StreamArray()))
> Traceback (most recent call last):
> File "pusher.py", line 43, in <module>
> sock.send(json.dumps(StreamArray()))
> ...
> MemoryError
"MemoryError" means that the operating system could not provide
as much memory as required.
This is a bit surprising as you seem to try to dump a newly
build object. But, maybe, your objects starts huge right from the
beginning?
> if use this solution, got another error
>
> combobject = getcombinations()
> sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
>
> Traceback (most recent call last):
> ...
> sock.send(json.dumps(combobject, cls=PythonObjectEncoder))
> ...
> TypeError: can't pickle generator objects
Apply "list" to your generator before dumping, i.e.
sock.send(json.dumps(list(combobject), ...))
Note in addition, that you can get a file like object from a socket
and then use "json.dump" (rather then "json.dumps"). This might (!)
better hanlde huge objects.
More information about the Python-list
mailing list