GithubHelp home page GithubHelp logo

tonysimpson / nanomsg-python Goto Github PK

View Code? Open in Web Editor NEW
382.0 31.0 85.0 84 KB

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy

License: MIT License

C 29.90% Python 68.48% Batchfile 1.62%

nanomsg-python's Introduction

nanomsg-python

Python library for nanomsg which does not compromise on usability or performance.

Like nanomsg this library is still experimental, the API is fairly stable but if you plan to use it at this time be prepared to get your hands dirty, fixes and enhancements are very welcome.

The following versions of Python are supported CPython 2.6+, 3.2+ and Pypy 2.1.0+

Bugs and change requests can be made here.

nanommsg library in /usr/local

If you're nanomsg is in /usr/local and your machine is not configured to find it there you can rename the usr_local_setup.cfg to setup.cfg to fix the problem.

Example

from __future__ import print_function
from nanomsg import Socket, PAIR, PUB
s1 = Socket(PAIR)
s2 = Socket(PAIR)
s1.bind('inproc://bob')
s2.connect('inproc://bob')
s1.send(b'hello nanomsg')
print(s2.recv())
s1.close()
s2.close()

Or if you don't mind nesting you can use Socket as a context manager

with Socket(PUB) as pub_socket:
    .... do something with pub_socket
# socket is closed

The lower level API is also available if you need the additional control or performance, but it is harder to use. Error checking left out for brevity.

from nanomsg import wrapper as nn_wrapper
from nanomsg import PAIR, AF_SP

s1 = nn_wrapper.nn_socket(AF_SP, PAIR)
s2 = nn_wrapper.nn_socket(AF_SP, PAIR)
nn_wrapper.nn_bind(s1, 'inproc://bob')
nn_wrapper.nn_connect(s2, 'inproc://bob')
nn_wrapper.nn_send(s1, b'hello nanomsg', 0)
result, buffer = nn_wrapper.nn_recv(s2, 0)
print(bytes(buffer))
nn_wrapper.nn_term()

License

MIT

Authors

Tony Simpson

nanomsg-python's People

Contributors

ch00k avatar codypiersall avatar drewcrawford avatar federicoceratto avatar jb098 avatar jbester avatar kubo39 avatar romanoved avatar tailhook avatar tonysimpson avatar tonysimpson-sky avatar vaibhavsagar avatar wtfuzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nanomsg-python's Issues

TypeError on Python 3.4.3

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'>

Error on binding sockets in python 3.6

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.

Unable to bind inside a Process

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).

Could not load the default wrapper for your platform: cpy, performance may be affected!

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?

connection timeout

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())

Can not get recv_fd

1

Always receive exception, I delete the highlight part, it works.
Any update?when?

Installation problems in Centos 6.5

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

No PyPI distribution

It'd be make adoption easier if nanomsg-python was being distributed on PyPI.

has warning

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,))

Travis CI support

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.

Install is a little finicky on OSX

I've noticed that installs are particularly finicky on OSX.

Suppose this configuration:

  1. nanomsg 0.4 installed via homebrew (to /usr/local/lib/libnanomsg.* and /usr/include/nanomsg)
  2. Python 3.4 from python.org

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

How to use low-level API for nn_recvmsg?

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?

warning "already imported from" when trying to import

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?

Future of nanomsg-python

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

  1. Building the module is requires more knowledge of building C projects than I think is reasonable;
  2. nanomsg has some unfixed bugs

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

Enhancing nanomsg module files structure to be containable.

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.

nanomsg-1 0-cp27-none-win32 whl

nanomsg.NanoMsgAPIError: Invalid argument

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

Could not load the default wrapper

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?

Can not exec after pyinstaller package code

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

Package cannot be installed

$ 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

Use .dynlib on macosx instead of .so to load the library

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

Is this maintained?

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?

Under windows: OSError: [WinError 126] The specified module could not be found

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.

screen shot 2016-02-03 at 13 54 53

could someone shed some light on this?

with thanks

nonblocking ?

Hi,
Does this support nonblocking mode ? I'm thinking of using PAIR with it ..

S

nanomsg.lib not found

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.

import nanomsg ERROR

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]

Support gevent and/or other event loops

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.

_nanomsg_cpy/wrapper.c(4) : fatal error C1083: Cannot open include file: 'nanomsg/nn.h': No such file or directory

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!

Importing Issues: cannot open shared object file: No such file or directory

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?

Project maintainer lacks commitment to project

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:

  • references this issue;
  • updates the documentation and setup.py to reflect the new location of the repo and maintainer;
  • has some details of why you are motivated to maintain the project, how you are qualified and what you would like to improve, just a few bullet points will do.

Thanks all and sorry that I haven't been able to prioritize nanomsg-python myself.

"python setup.py install" has error

_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.

Segmentation Fault

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 ()

IPC PUB-SUB protocol doesn't work

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.

New release to PyPI?

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.

Unable to install nanomsg on mac os x.

OS details

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#

nanomsg-python Version Details

<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#

Installation process

<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#

Error details 💣

<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. 👿

NameError: name 'nn_shutdown' is not defined

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

TypeError: must be str, not bytes in Python 3.3.3

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?

Examples

Can you post a few examples? There seems to be no documentation, anywhere, on how to use nanomsg from Python.

Doesn't work on OS X

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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.