Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70268
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'json': 0.07; 'parser': 0.07; 'source.': 0.07; 'sys': 0.07; 'complicate': 0.09; 'processing,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'structure,': 0.09; 'try:': 0.09; 'python': 0.11; 'def': 0.12; '(it': 0.16; '999': 0.16; 'bytearray': 0.16; 'hard-coded': 0.16; 'json,': 0.16; 'list),': 0.16; 'mine.': 0.16; 'nesting': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'reverses': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'stack': 0.19; '>>>': 0.22; 'import': 0.22; '(in': 0.22; 'header:User- Agent:1': 0.23; 'question': 0.24; 'source': 0.25; 'developers': 0.25; 'handling': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'url:bugs': 0.29; 'generally': 0.29; 'code': 0.31; 'apparently': 0.31; 'assert': 0.31; 'assumes': 0.31; 'existence': 0.31; 'fault': 0.31; 'pickle': 0.31; 'seemingly': 0.31; 'file': 0.32; 'probably': 0.32; 'url:python': 0.33; 'core': 0.34; 'maybe': 0.34; 'could': 0.34; 'problem': 0.35; 'except': 0.35; 'etc.)': 0.35; 'but': 0.35; 'recipient.': 0.36; 'subject:data': 0.36; 'url:org': 0.36; 'too': 0.37; 'list': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'easy': 0.60; '2nd': 0.60; 'increased': 0.61; "you're": 0.61; "you'll": 0.62; 'high': 0.63; 'choose': 0.64; 'investment': 0.66; 'price': 0.69; 'limit': 0.70; 'increase': 0.74; 'transfer': 0.82; '994': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: MemoryError in data conversion |
| Date | Tue, 15 Apr 2014 11:59 +0200 |
| Organization | None |
| References | <lifelc$ccj$1@news.albasani.net> <mailman.9239.1397461622.18130.python-list@python.org> <ligk5n$3jp$1@news.albasani.net> <mailman.9250.1397484008.18130.python-list@python.org> <lihjf0$4t6$1@news.albasani.net> <br3ajeFdnj3U1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd801a.dip0.t-ipconnect.de |
| User-Agent | KNode/4.11.5 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9278.1397555958.18130.python-list@python.org> (permalink) |
| Lines | 76 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1397555958 news.xs4all.nl 2900 [2001:888:2000:d::a6]:40361 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70268 |
Show key headers only | View raw
Gregory Ewing wrote: > Mok-Kong Shen wrote: >> I have yet a question out of curiosity: Why is my 2nd list structure, >> that apparently is too complex for handling by eval and json, seemingly >> not a problem for pickle? > > Pickle is intended for arbitrary data structures, so it > is designed to be able to handle deeply-nested and/or > recursive data. Eval only has to handle nesting to depths > likely to be encountered in source code. Apparently the > json parser also assumes you're not going to be using > very deep nesting. But pickle does have the same limitation: >>> def check(load, dump): ... items = [] ... try: ... for i in range(10**6): ... assert load(dump(items)) == items ... items = [items] ... except RuntimeError: ... return i ... >>> check(json.loads, json.dumps) 994 >>> check(pickle.loads, pickle.dumps) 499 Mok-Kong Shen, for pickle and json you can increase the limit a bit: >>> import sys >>> sys.setrecursionlimit(2000) >>> check(json.loads, json.dumps) 1994 >>> check(pickle.loads, pickle.dumps) 999 But be careful, if you choose the limit too high you'll see Python react like any other C program: >>> sys.setrecursionlimit(100000) >>> items = [] >>> for i in range(100000): ... items = [items] ... >>> s = pickle.dumps(items) Segmentation fault For literal_eval() the limit is unfortunately hard-coded in the C source. Mok-Kong Shen wrote: > What I need is to have my (complicated) list to be put into > a bytearray, do some proceesing, transfer it to the recipient. > The recipient reverses the processing, obtains a bytearray > that is the same as my original one and gets from it the same > list as mine. Using pickle I can manage to do it (in fact I > did try and succeed with my 2nd list), but that's IMHO a > rather unnatural/awkward work-around. (It means that I have > to pickle out the list to a file and read in the content of > the file in order to have it as a bytearray etc. etc.) The limit has been increased before, see http://bugs.python.org/issue1881 and maybe you can get the core developers to increase it again, but generally speaking the existence of a recursion limit is the price you pay for easy interfacing with C. literal_eval() could allocate its stack dynamically, but that would probably complicate the code so that return on investment is questionable.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
MemoryError in data conversion Mok-Kong Shen <mok-kong.shen@t-online.de> - 2014-04-14 03:46 +0200
Re: MemoryError in data conversion dieter <dieter@handshake.de> - 2014-04-14 08:14 +0200
Re: MemoryError in data conversion Peter Otten <__peter__@web.de> - 2014-04-14 09:46 +0200
Re: MemoryError in data conversion Mok-Kong Shen <mok-kong.shen@t-online.de> - 2014-04-14 14:26 +0200
Re: MemoryError in data conversion Peter Otten <__peter__@web.de> - 2014-04-14 15:59 +0200
Re: MemoryError in data conversion Mok-Kong Shen <mok-kong.shen@t-online.de> - 2014-04-14 23:20 +0200
Re: MemoryError in data conversion Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-15 11:51 +1200
Re: MemoryError in data conversion Mok-Kong Shen <mok-kong.shen@t-online.de> - 2014-04-15 10:55 +0200
Re: MemoryError in data conversion Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-16 00:08 +1200
Re: MemoryError in data conversion Peter Otten <__peter__@web.de> - 2014-04-15 11:59 +0200
Re:MemoryError in data conversion Dave Angel <davea@davea.name> - 2014-04-14 08:42 -0400
csiph-web