tonysimpson / nanomsg-python Goto Github PK
View Code? Open in Web Editor NEWnanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
License: MIT License
nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
License: MIT License
I'm trying to use nanomsg because ZMQ doesn't have a good implementation in Rust. However, I'm having trouble finding the Python library. I cannot compile pynng on my Mac M1 and this library has only one version (1.0.0) available in PIP and doesn't have any description.
Are you still maintaining this library or are there any good Python bindings?
I'm hoping this will help others, though I should note this only applies to *nix systems. After building nanomsg from source and installing this package via pip install
, I hit a warning and an error when I tried to import.
...
UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
...
OSError: libnanomsg.so: cannot open shared object file: No such file or directory
I figured, I shouldn't get the warning from Cpython, and shouldn't get the error as I did install the library (libnanomsg.so) via sudo make install
After a little digging, I found this question on SO.
I checked out my library linking paths
echo $LD_LIBRARY_PATH
and it was empty. I added a path to where libnanomsg.so installs itself.
export LD_LIBRARY_PATH=/usr/local/lib
and all was well with the world. This is a pretty temporary work around; is there a way we could build the library with the package? maybe use pyzmq as a model?
Hi,
Does this support nonblocking mode ? I'm thinking of using PAIR with it ..
S
uname -a
<hostname>:nanomsg-python root# uname -a Darwin <hostname>.home 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64 <hostname>:nanomsg-python root#
<hostname>:downloads root# git clone https://github.com/tonysimpson/nanomsg-python.git
Cloning into 'nanomsg-python'...
remote: Counting objects: 262, done.
remote: Total 262 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (262/262), 48.17 KiB | 0 bytes/s, done.
Resolving deltas: 100% (117/117), done.
Checking connectivity... done.
<hostname>:downloads root# cd nanomsg-python/
<hostname>:nanomsg-python root# git log --oneline --graph | head
* 742d39a Fixed test on 2.6
* 5fcd574 Merge branch 'jstasiak-master'
|\
| * 0b48e20 Merge
|/
* d89104e Merge pull request #19 from vaibhavsagar/patch-1
|\
| * 3838aba Update README.md
|/
* 6ffa74d Merge pull request #16 from drewcrawford/drew-vanilla
<hostname>:nanomsg-python root#
<host_name>:nanomsg-python root# python setup.py install --dry-run
running install
running bdist_egg
running egg_info
creating nanomsg.egg-info
writing nanomsg.egg-info/PKG-INFO
writing top-level names to nanomsg.egg-info/top_level.txt
writing dependency_links to nanomsg.egg-info/dependency_links.txt
writing manifest file 'nanomsg.egg-info/SOURCES.txt'
reading manifest file 'nanomsg.egg-info/SOURCES.txt'
writing manifest file 'nanomsg.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-intel/egg
running install_lib
running build_py
creating build
creating build/lib.macosx-10.9-intel-2.7
creating build/lib.macosx-10.9-intel-2.7/nanomsg
copying nanomsg/__init__.py -> build/lib.macosx-10.9-intel-2.7/nanomsg
copying nanomsg/version.py -> build/lib.macosx-10.9-intel-2.7/nanomsg
copying nanomsg/wrapper.py -> build/lib.macosx-10.9-intel-2.7/nanomsg
creating build/lib.macosx-10.9-intel-2.7/_nanomsg_ctypes
copying _nanomsg_ctypes/__init__.py -> build/lib.macosx-10.9-intel-2.7/_nanomsg_ctypes
creating build/lib.macosx-10.9-intel-2.7/nanomsg_wrappers
copying nanomsg_wrappers/__init__.py -> build/lib.macosx-10.9-intel-2.7/nanomsg_wrappers
running build_ext
building '_nanomsg_cpy' extension
creating build/temp.macosx-10.9-intel-2.7
creating build/temp.macosx-10.9-intel-2.7/_nanomsg_cpy
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _nanomsg_cpy/wrapper.c -o build/temp.macosx-10.9-intel-2.7/_nanomsg_cpy/wrapper.o
_nanomsg_cpy/wrapper.c:4:10: fatal error: 'nanomsg/nn.h' file not found
#include <nanomsg/nn.h>
^
1 error generated.
===============================================================================
WARNING : CPython API extension could not be built.
Exception was : CompileError(DistutilsExecError("command 'cc' failed with exit status 1",),)
If you need the extensions (they may be faster than alternative on some
platforms) check you have a compiler configured with all the necessary
headers and libraries.
===============================================================================
creating build/bdist.macosx-10.9-intel
creating build/bdist.macosx-10.9-intel/egg
creating build/bdist.macosx-10.9-intel/egg/_nanomsg_ctypes
copying build/lib.macosx-10.9-intel-2.7/_nanomsg_ctypes/__init__.py -> build/bdist.macosx-10.9-intel/egg/_nanomsg_ctypes
creating build/bdist.macosx-10.9-intel/egg/nanomsg
copying build/lib.macosx-10.9-intel-2.7/nanomsg/__init__.py -> build/bdist.macosx-10.9-intel/egg/nanomsg
copying build/lib.macosx-10.9-intel-2.7/nanomsg/version.py -> build/bdist.macosx-10.9-intel/egg/nanomsg
copying build/lib.macosx-10.9-intel-2.7/nanomsg/wrapper.py -> build/bdist.macosx-10.9-intel/egg/nanomsg
creating build/bdist.macosx-10.9-intel/egg/nanomsg_wrappers
copying build/lib.macosx-10.9-intel-2.7/nanomsg_wrappers/__init__.py -> build/bdist.macosx-10.9-intel/egg/nanomsg_wrappers
byte-compiling build/bdist.macosx-10.9-intel/egg/_nanomsg_ctypes/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.9-intel/egg/nanomsg/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.9-intel/egg/nanomsg/version.py to version.pyc
byte-compiling build/bdist.macosx-10.9-intel/egg/nanomsg/wrapper.py to wrapper.pyc
byte-compiling build/bdist.macosx-10.9-intel/egg/nanomsg_wrappers/__init__.py to __init__.pyc
creating build/bdist.macosx-10.9-intel/egg/EGG-INFO
copying nanomsg.egg-info/PKG-INFO -> build/bdist.macosx-10.9-intel/egg/EGG-INFO
copying nanomsg.egg-info/SOURCES.txt -> build/bdist.macosx-10.9-intel/egg/EGG-INFO
copying nanomsg.egg-info/dependency_links.txt -> build/bdist.macosx-10.9-intel/egg/EGG-INFO
copying nanomsg.egg-info/top_level.txt -> build/bdist.macosx-10.9-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/nanomsg-1.0a2-py2.7-macosx-10.9-intel.egg' and adding 'build/bdist.macosx-10.9-intel/egg' to it
removing 'build/bdist.macosx-10.9-intel/egg' (and everything under it)
Processing nanomsg-1.0a2-py2.7-macosx-10.9-intel.egg
Removing /Library/Python/2.7/site-packages/nanomsg-1.0a2-py2.7-macosx-10.9-intel.egg
Copying nanomsg-1.0a2-py2.7-macosx-10.9-intel.egg to /Library/Python/2.7/site-packages
nanomsg 1.0a2 is already the active version in easy-install.pth
Installed /Library/Python/2.7/site-packages/nanomsg-1.0a2-py2.7-macosx-10.9-intel.egg
Processing dependencies for nanomsg==1.0a2
Finished processing dependencies for nanomsg==1.0a2
<host_name>:nanomsg-python root#
<host_name>:nanomsg-python root# grep -ir '#include <nanomsg/nn.h>' *
_nanomsg_cpy/wrapper.c:#include <nanomsg/nn.h>
<host_name>:nanomsg-python root# find . -type f -name *nn.h* -print
<host_name>:nanomsg-python root#
Note that the repo does not have the nn.h header file. 👿
bind
throws TypeError
on Python 3.4.3 if I pass in a string. It works if I pass in a bytes
instead. I think both should work by automatically converting between them inside of bind
. It's not intuitive for the user to do the encoding.
Python 3.4.3+ (default, Oct 10 2015, 09:15:38)
Type "copyright", "credits" or "license" for more information.
IPython 4.1.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import nanomsg
/home/lyt/.virtualenvs/e3/lib/python3.4/site-packages/nanomsg_wrappers/__init__.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
"%s, performance may be affected!") % (default,))
In [2]: s1 = nanomsg.Socket(nanomsg.PAIR)
In [3]: s1.bind('inproc://a')
---------------------------------------------------------------------------
ArgumentError Traceback (most recent call last)
<ipython-input-3-ec2f3e46907a> in <module>()
----> 1 s1.bind('inproc://a')
/home/lyt/.virtualenvs/e3/lib/python3.4/site-packages/nanomsg/__init__.py in bind(self, address)
271 raise ValueError("Nanoconfig address must be sole endpoint")
272 endpoint_id = _nn_check_positive_rtn(
--> 273 wrapper.nn_bind(self._fd, address)
274 )
275 ep = Socket.BindEndpoint(self, endpoint_id, address)
ArgumentError: argument 2: <class 'TypeError'>: wrong type
In [4]: s1.bind(b'inproc://a')
Out[4]: <BindEndpoint socket <Socket fd 0, connected to [b'inproc://a'], bound to []>, id 1, addresss b'inproc://a'>
I try to run "python setup.py build" at windows7 command line, but an error happened: "_nanomsg_cpy/wrapper.c(4) : fatal error C1083: Cannot open include file: 'nanomsg/nn.h': No such file or directory."
The nanomsg is installed at C:\nanomsg, and I found the nn.h file is located at: C:\nanomsg\src
How can I let python konw the nanomsg path?
My enviroment is nanomsg-0.6-beta, python 3.4 32 bit, visual studio c++ express 2010, windows 7 64 bit.
Who can tell me how to do it? I'm a newer at python. thanks.
Best Regards!
There is currently no way to get or set headers manually on raw sockets
Filling this issue against myself :)
A new maintainer is required for the nanomsg-python project as the current maintainer has no motivation to do so.
I still feel that nanomsg is a promising design but at this time I don't have any projects I will be using it on.
If you would like to take over as maintainer please raise a pull request which:
Thanks all and sorry that I haven't been able to prioritize nanomsg-python myself.
When trying to install on OS X, I get the following error:
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 43, in <module>
_lib = ctypes.windll.nanoconfig
AttributeError: 'module' object has no attribute 'windll'
The problem appears to be this line in setup.py
:
if 'win' in sys.platform:
Because Python on OS X reports "darwin" as the platform:
>>> sys.platform
'darwin'
It'd be make adoption easier if nanomsg-python was being distributed on PyPI.
I might be missing something obvious, but running the example on the site produces this error:
In [32]: %paste
from nanomsg import Socket, PAIR, PUB
s1 = Socket(PAIR)
s2 = Socket(PAIR)
s1.bind('inproc://bob')
## -- End pasted text --
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-32-f1de1a8bf76f> in <module>()
2 s1 = Socket(PAIR)
3 s2 = Socket(PAIR)
----> 4 s1.bind('inproc://bob')
/home/user/environments/python3/lib/python3.3/site-packages/nanomsg-1.0a2-py3.3-linux-x86_64.egg/nanomsg/__init__.py in bind(self, address)
266 raise ValueError("Nanoconfig address must be sole endpoint")
267 endpoint_id = _nn_check_positive_rtn(
--> 268 wrapper.nn_bind(self._fd, address.encode())
269 )
270 ep = Socket.BindEndpoint(self, endpoint_id, address)
TypeError: must be str, not bytes
Since encode() will always return bytes in Python 3, will this not always fail?
from nanomsg import Socket, PAIR, SOL_SOCKET, RCVTIMEO
import time
s1 = Socket(PAIR)
s1.recv_timeout = 100
s1.connect('tcp://127.0.0.1:9099')
s1.recv_timeout = 100 <--- this line is wrong
Traceback (most recent call last):
File "/mnt/d/mypython/mynanomsg/nanomsg_pair_linux.py", line 5, in
s1.recv_timeout = 100
File "/root/.pyenv/versions/3.7.4/lib/python3.7/site-packages/nanomsg-1.0-py3.7-linux-x86_64.egg/nanomsg/init.py", line 245, in _set_recv_timeout
return self.set_int_option(SOL_SOCKET, RCVTIMEO, value)
File "/root/.pyenv/versions/3.7.4/lib/python3.7/site-packages/nanomsg-1.0-py3.7-linux-x86_64.egg/nanomsg/init.py", line 376, in set_int_option
buf))
File "/root/.pyenv/versions/3.7.4/lib/python3.7/site-packages/nanomsg-1.0-py3.7-linux-x86_64.egg/nanomsg/init.py", line 63, in _nn_check_positive_rtn
raise NanoMsgAPIError()
nanomsg.NanoMsgAPIError: Invalid argument
Example:
sock = Socket(REQ)
sock.bind('ipc://xyz') # succeeds on cpy, fails on ctypes
sock.bind(b'ipc://xyz') # fails on cpy, succeeds on ctypes
OSError: libnanomsg.so: cannot open shared object file: No such file or directory
I get an error when calling shutdown on an endpoint:
$ cat tmp.py
import nanomsg
socket = nanomsg.Socket(nanomsg.PAIR)
endpoint = socket.bind('inproc://foo')
endpoint.shutdown()
$ python tmp.py
Traceback (most recent call last):
File "tmp.py", line 5, in <module>
endpoint.shutdown()
File "/home/dbn/usr/lib/python3.4/site-packages/nanomsg/__init__.py", line 140, in shutdown
_nn_check_positive_rtn(nn_shutdown(self._fdocket._s,
NameError: name 'nn_shutdown' is not defined
Hello,
On mac osx (at least 10.9.5) nanomsg once installed had .dynlib extension.
In current code, the python wrapper try to load .so file, without success.
The code below correct the behaviour:
In _nanomsg_ctypes/init.py
if sys.platform in ('win32', 'cygwin'):
_functype = ctypes.WINFUNCTYPE
_lib = ctypes.windll.nanomsg
elif sys.platform in ('darwin'):
_functype = ctypes.CFUNCTYPE
_lib = ctypes.cdll.LoadLibrary('libnanomsg.dynlib')
else:
_functype = ctypes.CFUNCTYPE
_lib = ctypes.cdll.LoadLibrary('libnanomsg.so')
Regards,
Laurent
See PEP 3151 for details on exceptions.
In particular it would be nice to raise BlockingIOError and InterruptedError. I'm not sure whether we should subclass them or just use raw built-in classes.
I want to connect to multiple asynchronous ports. I could not find the python documentation for this library.
It seems there is some effort, but currently it doesn't work.
Travis could be used to test not only 4 python versions, but also with optional C extension and optional nanoconfig.
Let me know, if you need any help with this.
Hi Tony,
Thank you for this module. Though i haven't use it that much , however , building and installing nanomsg and nanomsg-python was a struggling for me since i am a windows user. My interest in nanomsg is that it support IOCP for asynchronous networks messaging.
I have compiled nanomsg (DLL and cpython extension ) and pack it as Wheel file.
In this regards , i mode some modification as follows:
1- Compiled the nanomsg C code using GCC 4.9.2 and rename the file to nanomsg.dll.
2- moved each of nanomsg.dll , _nanomsg_cpy.pyd and _nanomsg_ctypes to nanomsg_wrappers folder.
3- modified the code of nanomsg_wrappers/__init__py to import each _nanomsg_cpy.pyd and _nanomsg_ctypes from its current local folder rather from site-package main folder. later , it would be possible to have a nanomsg_cffi within the same folder.
So the package of nanomsg is contained in three folder rather four and _nanomsg_cpy.pyd file.
This make it simpler to follow rather than searching distributed files within system path, Since not all windows users who program in python knows the C/C++ modules compilation requirements; they just like to install and use.
Attached within this post the wheel file , just remove the PNG extension and use "pip install nanomsg-1.0-cp27-none-win32.whl" .
I have tested the packages , other testers are welcome.
Kindly , upload it to PyPi to allow other Python programmers to use with it less compiling complications.
take care.
PyCharm cannot find declaration of PAIR, SUB and other protocol types.
This is accomplished by pyzmq in the pyzmq.green module. Theoretically, an integration could be accomplished using nn_poll, however those docs make a reference to integrating with other event loops in the NOTE section, so a more efficient integration should be possible.
This is something I hope to look into if I can find the time, but perhaps someone else has a better lead on the subject.
I get a segmentation fault from the following erroneous code using Python 3.3.0
from nanomsg import Socket, REP, REQ
s1 = Socket(REQ)
s2 = Socket(REP)
s1.bind('inproc://hello')
s2.bind('inproc://hi')
s1.close()
s1.connect('inproc://hi')
When I run GDB, it gives me the following backtrace
(gdb) run crash.py
Starting program: /usr/bin/python3 crash.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff0d0e700 (LWP 7850)]
Program received signal SIGSEGV, Segmentation fault.
0x00000039da809b70 in pthread_mutex_lock () from /lib64/libpthread.so.0
(gdb) bt
#0 0x00000039da809b70 in pthread_mutex_lock () from /lib64/libpthread.so.0
#1 0x00007ffff0f478d3 in nn_mutex_lock (self=self@entry=0x1489)
at src/utils/mutex.c:70
#2 0x00007ffff0f42a15 in nn_ctx_enter (self=self@entry=0x1489)
at src/aio/ctx.c:48
#3 0x00007ffff0f4130a in nn_sock_add_ep (self=0x1411,
transport=0x7ffff1163360 <nn_inproc_vfptr>, bind=bind@entry=0,
addr=0x7ffff15c9b69 "hi") at src/core/sock.c:475
#4 0x00007ffff0f3db3f in nn_global_create_ep (s=s@entry=-1,
addr=<optimized out>, addr@entry=0x7ffff15c9b60 "inproc://hi",
bind=bind@entry=0) at src/core/global.c:1101
#5 0x00007ffff0f3e2ea in nn_connect (s=-1, addr=0x7ffff15c9b60 "inproc://hi")
at src/core/global.c:617
#6 0x00007ffff11658a5 in _nanomsg_cpy_nn_connect (self=<optimized out>,
args=<optimized out>) at _nanomsg_cpy/wrapper.c:295
#7 0x00000034dbf0cc3e in PyEval_EvalFrameEx ()
from /lib64/libpython3.3m.so.1.0
#8 0x00000034dbf0c965 in PyEval_EvalFrameEx ()
from /lib64/libpython3.3m.so.1.0
#9 0x00000034dbf0de13 in PyEval_EvalCodeEx () from /lib64/libpython3.3m.so.1.0
#10 0x00000034dbf0dedb in PyEval_EvalCode () from /lib64/libpython3.3m.so.1.0
#11 0x00000034dbf2805f in run_mod () from /lib64/libpython3.3m.so.1.0
#12 0x00000034dbf29f7c in PyRun_FileExFlags () from /lib64/libpython3.3m.so.1.0
---Type <return> to continue, or q <return> to quit---
#13 0x00000034dbf2ac7d in PyRun_SimpleFileExFlags ()
from /lib64/libpython3.3m.so.1.0
#14 0x00000034dbf3f4d4 in Py_Main () from /lib64/libpython3.3m.so.1.0
#15 0x0000000000400b1f in main ()
After creating a socket, how can I find out that the connection path is available or not? Please see the following codes, assume that path
isn't available. How can I detect it after s1.connect(path)
?
s1 = Socket(PUSH)
s1.connect(path)
s1.send(makeCapnpPacket().to_bytes())
When I try to import nanomsg in python 2.7 I get the following:
$ import nanomsg
/usr/local/lib/python2.7/dist-packages/nanomsg-1.0-py2.7-linux-armv7l.egg/_nanomsg_cpy.py:3: UserWarning: Module _nanomsg_cpy was already imported from /usr/local/lib/python2.7/dist-packages/nanomsg-1.0-py2.7-linux-armv7l.egg/_nanomsg_cpy.pyc, but /home/pi/gitlibs/nanomsg-python is being added to sys.path
I installed using sudo python setup.py install. Any way to fix this warning?
$ python setup.py install
running install
running bdist_egg
running egg_info
writing nanomsg.egg-info/PKG-INFO
writing top-level names to nanomsg.egg-info/top_level.txt
writing dependency_links to nanomsg.egg-info/dependency_links.txt
reading manifest file 'nanomsg.egg-info/SOURCES.txt'
writing manifest file 'nanomsg.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.9-x86_64/egg
running install_lib
running build_py
Traceback (most recent call last):
File "setup.py", line 70, in <module>
test_suite="tests",
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/install.py", line 73, in run
self.do_egg_install()
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/install.py", line 93, in do_egg_install
self.run_command('bdist_egg')
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/bdist_egg.py", line 185, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/bdist_egg.py", line 171, in call_command
self.run_command(cmdname)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/install_lib.py", line 20, in run
self.build()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install_lib.py", line 109, in build
self.run_command('build_py')
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/build_py.py", line 89, in run
self.build_packages()
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_py.py", line 372, in build_packages
self.build_module(module, module_file, package)
File "/Users/nikolaykolev/.virtualenv/nanomsg/lib/python2.7/site-packages/setuptools/command/build_py.py", line 106, in build_module
outfile, copied = _build_py.build_module(self, module, module_file, package)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_py.py", line 333, in build_module
"'package' must be a string (dot-separated), list, or tuple")
TypeError: 'package' must be a string (dot-separated), list, or tuple
During install on win32, and building the wrapper, the nanomsg.lib is not found.
Adding the c:\program files (x86)\nanomsg\lib to the 'Extension' command option library_dirs it works.
ubuntu20.04
python3.8
Why this warning happend, I'm confused
Sorry to post it here, github doesn't allow me to DM author with this question.
I need to use low-level nn_recvmsg
with nn_iovec
and nn_msghdr
structures, but I'm not sure how to do it in Python. Can anyone suggest?
I install nanomsg with pip install nanomsg
, I got this waring:
/home/roger/anaconda/envs/crawler/lib/python2.7/site-packages/nanomsg_wrappers/__init__.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
"%s, performance may be affected!") % (default,))
and I have set up
export LD_LIBRARY_PATH=/usr/local/lib
what is wrong?
I follow the usual installation with setup.py:
python3 setup.py build_ext --include-dirs /usr/local/include --library-dirs=/usr/local/lib/
python3 setup.py install
but when I do import nanomsg I get:
import nanomsg
./nanomsg_wrappers/init.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
"%s, performance may be affected!") % (default,))
Traceback (most recent call last):
File "", line 1, in
File "./nanomsg/init.py", line 7, in
from . import wrapper
File "./nanomsg/wrapper.py", line 4, in
_wrapper = _load_wrapper()
File "./nanomsg_wrappers/init.py", line 23, in load_wrapper
return importlib.import_module('_nanomsg_ctypes')
File "/usr/lib64/python3.3/importlib/init.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "./_nanomsg_ctypes/init.py", line 13, in
_lib = ctypes.cdll.LoadLibrary('libnanomsg.so')
File "/usr/lib64/python3.3/ctypes/init.py", line 426, in LoadLibrary
return self._dlltype(name)
File "/usr/lib64/python3.3/ctypes/init.py", line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: libnanomsg.so: cannot open shared object file: No such file or directory
any ideas ???
would be great to have a "pip install nanomsg".
Thanks in advance
Following on from #43
I still do not have the time of motivation to maintain this project to the level it requires.
The are a couple of major problems with nanomsg and nanomsg-python
To solve both of these my plan is to take the nanomsg source code and "vendor" it with the python module so that building the module becomes a lot simpler and it would be easy to build and maintain pip wheels for windows so that no building is required. This would improve things a lot - I also plan to debug the long standing deadlock issues.
I started this work but don't have time to finish it at the moment - I think it will be 3 or 4 months before I find time to look at it again.
We can plod on as is but is anyone want to take over please reply here of message me on twitter @agjasimpson
Thank,
Tony
i need to get the established connections count~~~~but there is no nn_get_statistic wrapper.....
could you add it in new version??
Trying to test with IPC protocol, but messages are never received:
publisher:
>>> from nanomsg import Socket, PUB, SUB
>>> s = Socket(PUB)
>>> s.bind('ipc://test')
<BindEndpoint socket <Socket fd 0, connected to [], bound to ['ipc://test']>, id 1, address 'ipc://test'>
>>> s.send(b'test\n')
subscriber:
>>> from nanomsg import Socket, PUB, SUB
>>> s = Socket(SUB)
>>> s.connect('ipc://test')
<ConnectEndpoint socket <Socket fd 0, connected to ['ipc://test'], bound to []>, id 1, address 'ipc://test'>
>>> s.recv()
Is there anything Python-specific for IPC I'm missing out here? I tried nnpy - it doesn't work either.
C:\Python27\Lib\site-packages\nanomsg-1.0a2-py2.7-win-amd64.egg\nanomsg_wrappers__init__.py:22: UserWarning: Could not
load the default wrapper for your platform: cpy, performance may be affected!
"%s, performance may be affected!") % (default,))
Traceback (most recent call last):
File "F:\eclipse_projects\test\nanomsq_t1.py", line 3, in
import nanomsg
File "C:\Python27\Lib\site-packages\nanomsg-1.0a2-py2.7-win-amd64.egg\nanomsg__init__.py", line 7, in
from . import wrapper
File "C:\Python27\Lib\site-packages\nanomsg-1.0a2-py2.7-win-amd64.egg\nanomsg\wrapper.py", line 4, in
wrapper = load_wrapper()
File "C:\Python27\Lib\site-packages\nanomsg-1.0a2-py2.7-win-amd64.egg\nanomsg_wrappers__init.py", line 23, in load_
wrapper
return importlib.import_module('nanomsg_ctypes')
File "C:\Python27\lib\importlib__init_.py", line 37, in import_module
import(name)
File "C:\Python27\Lib\site-packages\nanomsg-1.0a2-py2.7-win-amd64.egg_nanomsg_ctypes__init__.py", line 10, in
lib = ctypes.windll.nanomsg
File "C:\Python27\lib\ctypes__init_.py", line 423, in getattr
dll = self.dlltype(name)
File "C:\Python27\lib\ctypes__init_.py", line 353, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126]
Some calls do not return anything where they should return the result of _nn_check_positive_rtn
.
A good example is the send()
method.
This makes it hard to test.
Ideally we would have all the calls follow the nanomsg specs:
http://nanomsg.org/v0.5/nanomsg.7.html
Thanks for all the work so far!
Example -
$ export NANOMSG_PY_TEST_ADDRESS='tcp://127.0.0.1:49234'
$ python test_pubsub.py #Hangs
$ python test_pair.py #Passes
Can you post a few examples? There seems to be no documentation, anywhere, on how to use nanomsg from Python.
I get the error " UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!".
Can and should I do something about it?
_nanomsg_cpy/wrapper.c:4:24: fatal error: nanomsg/nn.h: No such file or directory
#include <nanomsg/nn.h>
^
compilation terminated.
===============================================================================
WARNING : CPython API extension could not be built.
Exception was : CompileError(DistutilsExecError("command 'gcc' failed with exit status 1",),)
If you need the extensions (they may be faster than alternative on some
platforms) check you have a compiler configured with all the necessary
headers and libraries.
Hi, there
I wrote nn_pair test in this repo using py.test.
https://github.com/kubo39/nanomsg-python/tree/pytest
I changed setup.py and LD_LIBRARY_PATH for testing in Python2.7.3 with Ubuntu 12.04. May I ask for your review?
I tried to use nanomsg-python inside a Process (using multiprocessing.Process) with PIPELINE protocol (many clients PUSH to one server who PULLed).
I do not know why, the socket which must received messages does not work (and no logs or errors are returned from server side with NN_PRINT_ERRORS or NN_PRINT_STATISTICS).
But if I code the same thing using a thread, it works (replacing multiprocessing.Process with threading.Thread in the following code).
Is there any incidence with how processes are managed with python ?
For instance you can use the following code for a server which PULLed nanomsg socket to reproduce the issue.
import nanomsg, multiprocessing
class ServerSocket(multiprocessing.Process):
def __init__(self, server):
super(ServerSocket, self).__init__()
self.daemon = True
self.server=server
def on_receive(self, msg):
print msg
def run(self):
self.socket = nanomsg.Socket(nanomsg.PULL)
self.socket.bind(self.server)
while True:
msg=self.socket.recv()
self.on_receive(msg)
self.socket.close()
And after you can ue it with the following code
myserver=ServerSocket('tcp:\\*:12345')
myserver.start()
No socket seems to be created by nanomsg (no traces with NN_PRINT_STATISTICS set).
In nanomsg/init.py, line 219 ( https://github.com/tonysimpson/nanomsg-python/blob/master/nanomsg/__init__.py#L219 ), this code
recv_fd = property(_get_send_fd, doc='Receive file descripter')
should be:
recv_fd = property(_get_recv_fd, doc='Receive file descripter')
I was wondering if you could upload a new release to PyPI? It would be nice to have the poll support in particular added by PR #50.
hi,
i installed nanomsg-python with pip install nanomsg
, but when i try and import from it, i receive the following errors. my application works fine under OSX, and i'm only encountering this issue on windows.
from googling, i think the first line of the error might be diagnostic to someone who knows what it means.
could someone shed some light on this?
with thanks
nanomsg_wrappers/init.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
"%s, performance may be affected!") % (default,))
Hi.
I have tried to run a code that binds a socket in python2.7 in python3.6:
from nanomsg import REP, Socket, PAIR a = Socket(REP) a.bind("ipc://bla")
On python 2.7 the code works yet the output in python3.6 is:
/usr/local/lib/python3.6/dist-packages/nanomsg_wrappers/__init__.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected! "%s, performance may be affected!") % (default,)) Traceback (most recent call last): File "engine.py", line 5, in <module> a.bind("ipc://bla") File "/usr/local/lib/python3.6/dist-packages/nanomsg/__init__.py", line 273, in bind wrapper.nn_bind(self._fd, address) ctypes.ArgumentError: argument 2: <class 'TypeError'>: wrong type
I stumbled an old issue : #13
And according to it I changed the code to
from nanomsg import REP, Socket, PAIR a = Socket(REP) a.bind("ipc://bla".encode())
It seems to fix it.
I've noticed that installs are particularly finicky on OSX.
Suppose this configuration:
There's not a good way to install nanomsg-python from pip. For example you might naively try
pip3.4 install -e git+https://github.com/tonysimpson/nanomsg-python#egg=nanomsg
But it turns out that neither /usr/local/lib is in lib search path nor is /usr/include in include search path by default. Arguably this is somebody else's bug, but it's inconvenient.
The workaround is to download the repo yourself and specify manually with build_ext:
python3 setup.py build_ext --include-dirs /usr/local/include --library-dirs=/usr/local/lib/
python3 setup.py install
But for requirements.txt or other pip install, this is very unsatisfactory.
Finally, using python3 setup.py develop
in lieu of python3 setup.py install
is inexplicably broken; it installs without error but it fails to import.
I'm not totally sure what is afoot here, but I've seen this behavior on 2 systems now and so it may be worth investigating
Error log:
ImportError: No module named '_nanomsg_ctypes'
UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
I fixed it in nanomsg_wrappers/init.py add 2 lines:
import _nanomsg_ctypes import _nanomsg_cpy
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.