0

I am using Python 2.6 and facing the below exception:

Traceback (most recent call last):
  File "ProceraExporter_new.py", line 695, in <module>
    sendRecord(dictParseConfig,portList[0])
  File "ProceraExporter_new.py", line 610, in sendRecord
    dictRecord = proceraGen(dictParseConfig)
  File "ProceraExporter_new.py", line 539, in proceraGen
    exp = ProceraExporter(dictParseConfig)
  File "ProceraExporter_new.py", line 216, in __init__
    self.createHeaderToFuncMap()
  File "ProceraExporter_new.py", line 234, in createHeaderToFuncMap
    self.dictHeaderFuncMap['proceraApn'] = self.radiusCalledStationIdGenerator()
  File "ProceraExporter_new.py", line 490, in radiusCalledStationIdGenerator
    radiusCalledStationId = 'Sushfone-'+str(self.getRandomValue(start = 1, end = 5))
  File "ProceraExporter_new.py", line 291, in getRandomValue
    randomVal = adder + multiplier*random.randint(start, end)
  File "/usr/lib64/python2.6/random.py", line 228, in randint
    return self.randrange(a, b+1)
  File "/usr/lib64/python2.6/random.py", line 200, in randrange
    if width >= maxwidth:
SystemError: Objects/longobject.c:237: bad argument to internal function

From the trace, it can be seen that value of "start" is passed as 1 and "end" is passed as 5 which are integers, but still it is giving this exception.

Do you have any idea why this might occur?

Samarth
  • 627
  • 6
  • 13
  • Could you please write the code block that gives this error? – myildirim Jun 30 '14 at 09:03
  • @myildirim: you mean `getRandomValue()`? – Martijn Pieters Jun 30 '14 at 09:03
  • This is an internal error *in the Python C code*. Something more heinous is going on here, I don't think this is an error in your Python code. – Martijn Pieters Jun 30 '14 at 09:04
  • @MartijnPieters: Exactly. Actually, this code gets called multiple times. In the 1st iteration, it works just fine, but from the 2nd iteration onwards, the issue starts. Though the values that have been passed to the function are same. – Samarth Jun 30 '14 at 09:17
  • @Samarth: yes, so an internal state is being corrupted somewhere. What *exact* Python version is this? How was it installed? – Martijn Pieters Jun 30 '14 at 09:25
  • @MartijnPieters: Python version is 2.6.6. And it comes with the image of our build. – Samarth Jun 30 '14 at 09:47
  • The `width >= maxwidth` comparison compares an `int` with `long`, and it looks as if internally, Python is passing not an int but NULL to [`PyLong_AsLong`](http://hg.python.org/cpython/file/2.6/Objects/longobject.c#l225). This could either be the `width` integer (pointing to the cached integer object being corrupted) or to the `maxwidth` long object (no idea there). Both would mean *other code* has corrupted your Python interpreter state outside of these `randint()` calls. – Martijn Pieters Jun 30 '14 at 09:53
  • Do you mean to say that my script has corrupted the Python interpreter's state or some Python's internal working has corrupted it? – Samarth Jun 30 '14 at 10:29
  • @Samarth: Some other library or code you used has, in all likelyhood, corrupted some internal state. `width >= maxwidth` would *never* trigger a `SystemError` otherwise. Since [small integers are interned](http://stackoverflow.com/questions/306313/python-is-operator-behaves-unexpectedly-with-integers) and you can [hack those cached values](http://codegolf.stackexchange.com/a/28851), I am thinking something corrupted the small integers cache as a first suspect. – Martijn Pieters Jun 30 '14 at 10:33
  • Isn't there a way I can drill down to the root cause of this issue? – Samarth Jun 30 '14 at 11:07

0 Answers0