Simple python verticle error: NameError: name 'buffer' is not defined

1,553 views
Skip to first unread message

Amit Kumar

unread,
Jul 23, 2014, 4:58:40 PM7/23/14
to ve...@googlegroups.com
import vertx

from core.event_bus import EventBus

def handler(msg):
   
print 'Received message %s' % msg.body
   
# Now reply to it
    msg
.reply('Pong!')

EventBus.register_handler('ping-address', handler=handler)

def reply_handler(msg):
   
print 'Received reply %s' % msg.body

EventBus.send('ping-address', 'ping!', reply_handler)


The example above throws following exception. I am running on Mac OSX (Mavericks) with following environment :

Vert.x = 2.1.1, JYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7

Traceback (most recent call last):

 
File "test1.py", line 20, in <module>
 
File "test1.py", line 2, in f__VertxInternalVert__1
   
from core.event_bus import EventBus
 
File "__pyclasspath__/vertx.py", line 26, in <module>
 
File "__pyclasspath__/core/http.py", line 26, in <module>
 
File "__pyclasspath__/core/javautils.py", line 23, in <module>
 
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.py", line 36, in <module>
   
BufferType = buffer

NameError: name 'buffer' is not defined

Traceback (most recent call last):
 
File "test1.py", line 20, in <module>
 
File "test1.py", line 2, in f__VertxInternalVert__1
   
from core.event_bus import EventBus
 
File "__pyclasspath__/vertx.py", line 26, in <module>
 
File "__pyclasspath__/core/http.py", line 26, in <module>
 
File "__pyclasspath__/core/javautils.py", line 23, in <module>
 
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.py", line 36, in <module>

   
BufferType = buffer

NameError: name 'buffer' is not defined


Noticed: http://bugs.jython.org/issue1521 which seems to be a Jython bug. Any suggestions ? Am I using an incompatible version of Python ?

Jordan Halterman

unread,
Jul 23, 2014, 11:31:58 PM7/23/14
to ve...@googlegroups.com
You shouldn't really be pointing JYTHONPATH to your CPython library. I imagine Jython is loading CPython libraries which use the buffer protocol, but since that's not supported by Jython it's causing issues. 

Vert.x packages its own Jython build with some bug fixes in it, and it uses a ScriptBuilder to run the script. So, pointing the JYTHONPATH elsewhere serves only to confuse the Vert.x Jython interpreter by causing it to load potentially incompatible modules. I imagine it would be fine to point it to another Jython 2.5 installation, though.

Is that really all the code that's causing this? I guess Jython is loading some core module from CPython that uses buffer.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amit Kumar

unread,
Jul 24, 2014, 12:27:01 AM7/24/14
to ve...@googlegroups.com
Thanks Jordan. The reason I have set JYTHONPATH is to load existing python modules and work with them in my verticle. How else I would do it ? Yes, that is all the code I have for my test, though I intended to use other python modules in my verticle, I get the issue even without importing any other python module.

Amit Kumar

unread,
Jul 24, 2014, 12:31:05 AM7/24/14
to ve...@googlegroups.com

bash-3.2$ cat test1.py; vertx run test1.py


import vertx


from core.event_bus import EventBus




def handler(msg):


    print 'Received message %s' % msg.body


    # Now reply to it


    msg.reply('Pong!')




EventBus.register_handler('ping-address', handler=handler)




def reply_handler(msg):


    print 'Received reply %s' % msg.body




EventBus.send('ping-address', 'ping!', reply_handler)


Traceback (most recent call last):


  File "test1.py", line 20, in <module>


  File "test1.py", line 2, in f__VertxInternalVert__1


    from core.event_bus import EventBus


  File "__pyclasspath__/vertx.py", line 26, in <module>


  File "__pyclasspath__/core/http.py", line 26, in <module>


  File "__pyclasspath__/core/javautils.py", line 23, in <module>


  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.py", line 36, in <module>


    BufferType = buffer


NameError: name 'buffer' is not defined


 


Traceback (most recent call last):


  File "test1.py", line 20, in <module>


  File "test1.py", line 2, in f__VertxInternalVert__1


    from core.event_bus import EventBus


  File "__pyclasspath__/vertx.py", line 26, in <module>


  File "__pyclasspath__/core/http.py", line 26, in <module>


  File "__pyclasspath__/core/javautils.py", line 23, in <module>


  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/types.py", line 36, in <module>


    BufferType = buffer


NameError: name 'buffer' is not defined


 


bash-3.2$

Sending code again... 

Jordan Halterman

unread,
Jul 24, 2014, 12:51:51 AM7/24/14
to ve...@googlegroups.com
That makes sense. Accessing a lot of the modules in your CPython installation would be nice.

I think there could be a workaround for this. I know this JYTHONPATH issue comes up every now and then around here. I think I saw a patch in that issue you linked. Maybe we can patch the Vert.x Jython build if that patch is good enough. I noticed also that it said this was causing issues with using Twisted in Jython too, and while obviously no one would need to use Twisted with Vert.x, it sort of demonstrates that it might be worth the time to try to fix the buffer protocol issues in the Vert.x build.

I'll have to check out the patch this weekend. Or feel free to do the same if you find time. The Vert.x Jython fork is somewhere around the vert-x organization on GitHub.
Reply all
Reply to author
Forward
0 new messages