Giter Club home page Giter Club logo

nnpy's Introduction

Welcome to nanomsg

Release MIT License Linux Windows Darwin Discord

The nanomsg library is a simple high-performance implementation of several "scalability protocols". These scalability protocols are light-weight messaging protocols which can be used to solve a number of very common messaging patterns, such as request/reply, publish/subscribe, surveyor/respondent, and so forth. These protocols can run over a variety of transports such as TCP, UNIX sockets, and even WebSocket.

For more information check the website.

Prerequisites

  1. Windows.

    • Windows Vista or newer (Windows XP and 2003 are NOT supported)
    • Microsoft Visual Studio 2010 (including C++) or newer, or mingw-w64. (Specifically mingw and older Microsoft compilers are NOT supported, and we do not test mingw-w64 at all, so YMMV.)
    • CMake 2.8.12 or newer, available in $PATH as cmake
  2. POSIX (Linux, MacOS X, UNIX)

    • ANSI C compiler supporting C89
    • POSIX pthreads (should be present on all modern POSIX systems)
    • BSD sockets support for both TCP and UNIX domain sockets
    • CMake (http://cmake.org) 2.8.12 or newer, available in $PATH as cmake
  3. Documentation (optional)

Quick Build Instructions

These steps here are the minimum steps to get a default Debug build. Using CMake you can do many other things, including setting additional variables, setting up for static builds, or generation project or solution files for different development environments. Please check the CMake website for all the various options that CMake supports.

POSIX

This assumes you have a shell in the project directory, and have the cmake and suitable compilers (and any required supporting tools like linkers or archivers) on your path.

  1. % mkdir build
  2. % cd build
  3. % cmake ..
  4. % cmake --build .
  5. % ctest .
  6. % sudo cmake --build . --target install
  7. % sudo ldconfig (if on Linux)

Windows

This assumes you are in a command or powershell window and have the appropriate variables setup to support Visual Studio, typically by running vcvarsall.bat or similar with the appropriate argument(s). It also assumes you are in the project directory.

  1. md build
  2. cd build
  3. cmake ..
  4. cmake --build . --config Debug
  5. ctest -C Debug .
  6. cmake --build . --config Debug --target install NB: This may have to be done using an Administrator account.

Alternatively, you can build and install nanomsg using vcpkg dependency manager:

  1. git clone https://github.com/Microsoft/vcpkg.git
  2. cd vcpkg
  3. ./bootstrap-vcpkg.bat
  4. ./vcpkg integrate install
  5. ./vcpkg install nanomsg

The nanomsg port in vcpkg is kept up to date by microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Static Library

We normally build a dynamic library (.so or .DLL) by default.

If you want a static library (.a or .LIB), configure by passing -DNN_STATIC_LIB=ON to the first cmake command.

POSIX

POSIX systems will need to link with the libraries normally used when building network applications. For some systems this might mean -lnsl or -lsocket.

Windows

You will also need to define NN_STATIC_LIB in your compilation environment when building programs that use this library. This is required because of the way Windows changes symbol names depending on whether the symbols should be exported in a DLL or not.

When using the .LIB on Windows, you will also need to link with the ws2_32, mswsock, and advapi32 libraries, as nanomsg depends on them.

Support

This library is considered to be in "sustaining" mode, which means that new feature development has ended, and bug fixes are made only when strictly necessary for severe issues.

New development is now occurring in the NNG project, which offers both protocol and API compatibility with this project. Please consider using NNG for new projects.

Please see the file SUPPORT for more details.

nnpy's People

Contributors

0xe1e10 avatar aballier avatar bnewbold avatar djc avatar evadot avatar james-lawrence avatar lucasb-eyer avatar mayfield avatar rizo avatar ronnypfannschmidt avatar wrobell avatar xgdgsc 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

nnpy's Issues

Upload to pypi

Having nnpy on PyPi will benefit everyone who build package around it.
I think an sdist could be uploaded without any trouble.

Problem with sending a few messages in a row with different lengths

Hi @djc @mayfield @bnewbold

I am using nnpy to connect to my robot. It is at the following format:

push = nnpy.Socket(nnpy.AF_SP, nnpy.PUSH)
push.connect(rep_address)
str1 = '{"category":["Main","Tasks"],"name":"Command-1","data":{}}'
push.send(str1)
time.sleep(1)
push.close()

After sending this Command-1 as a message, I send some Command-2 (with a format similar to the above code) to do something else with the robot. But, since the length of the two messages is different (for example the second message is shorter), there will be some unknown characters at the end of the second message when I send it and the robot does not recognize it.

I tried to solve this by adding a lot of spaces at the end of the second message line (because my messages are somehow considered as JSON), but it becomes intractable when the number of commands goes to around 10 (I also tried to make it smarter by comparing the length of each message with the maximum length of the messages being sent before that, and add extra spaces at the end of the message if it's shorter than the max, but still doesn't work all the time!).

So, I thought a better idea could be available for this issue. It seems that there is a buffer-like variable that the messages are being overwritten on that. If so, that could be resolved if I have access to that variable to clear it every time before sending a new message.

Please let me know if you think different, or you have any idea to resolve this issue.
Thanks

test.py doesn't run

OS: Kubuntu 20.04

To recreate:

git clone https://github.com/nanomsg/nnpy.git
cd nnpy/nnpy
python tests.py

This produces the output::

Traceback (most recent call last):
  File "tests.py", line 2, in <module>
    import filecmp, nnpy, sys, unittest
  File "build/bdist.linux-x86_64/egg/nnpy/__init__.py", line 2, in <module>
    from _nnpy import ffi, lib as nanomsg
  File "build/bdist.linux-x86_64/egg/_nnpy.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/_nnpy.py", line 3, in __bootstrap__
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 36, in <module>
    import email.parser
  File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
    from email.feedparser import FeedParser
  File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
    from email import message
  File "/usr/lib/python2.7/email/message.py", line 16, in <module>
    import email.charset
  File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
    import email.base64mime
  File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
    from email.utils import fix_eols
  File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
    import socket
  File "/home/nnpy/nnpy/socket.py", line 1, in <module>
    from . import errors, ffi, nanomsg
ValueError: Attempted relative import in non-package

This is because the directory that the tests are being run in takes precedence for imports and class declarations. This can be observed in the lines:

...
  File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
    import socket
...

There are three options:

  1. Move test,py to nnpy/
  2. Create an nnpy/test/ directory and move it there
  3. Create an nnpy/nnpy/test/ directory and move it there

I think option 3 is preferable

No support for NN_DONTWAIT?

That the NN_DONTWAIT constant isn't defined anywhere the nnpy lib is a hint enough of it being unsupported, but if I try to pass it nonetheless, I'm getting AssertionError:

In [16]: pair.recv(flags=1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-16-35a907a09301> in <module>()
----> 1 pair.recv(flags=1)

./lib/python2.7/site-packages/nnpy/socket.pyc in recv(self, flags)
     62         buf = ffi.new('char**')
     63         rc = nanomsg.nn_recv(self.sock, buf, NN_MSG, flags)
---> 64         assert rc > 0, rc
     65         s = ffi.buffer(buf[0], rc)[:]
     66         nanomsg.nn_freemsg(buf[0])

AssertionError: -1

It looks like adding it wouldn't be much work. Is there a chance of it happening?

build fails with recent nanomsg

I tried to install nnpy for the first time today, with a fresh checkout of nanomsg installed (9b7f444d2...).

I get the following error:

bnewbold@ent$ python setup.py build
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    generate.run()
  File "/home/bnewbold/src/nnpy/generate.py", line 55, in run
    f.write(symbols(headers))
  File "/home/bnewbold/src/nnpy/generate.py", line 33, in symbols
    ffi.cdef(headers)
  File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 103, in cdef
    self._parser.parse(csource, override=override, packed=packed)
  File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 166, in parse
    self._internal_parse(csource)
  File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 172, in _internal_parse
    ast, macros, csource = self._parse(csource)
  File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 129, in _parse
    self.convert_pycparser_error(e, csource)
  File "/usr/local/lib/python2.7/dist-packages/cffi/cparser.py", line 158, in convert_pycparser_error
    raise api.CDefError(msg)
cffi.api.CDefError: cannot parse "int nn_req_send (int s, nn_req_handle hndl, const void *buf, size_t len, int flags);"
:3:25: before: nn_req_handle

I think the problem is that generate.py isn't including a typedef for nn_req_handle in the autogenerated nnpy/nanomsg.h, but i'm not sure if the fix would be as simple as including that.

Add support for asyncio

It would be great to support asyncio.

Asyncio socket class implementation (depends on #25) with sample usage below. This is bit hacky implementation

  • send and recv methods are coroutines
  • file descriptors of SP sockets are watched with loop.add_reader and loop.add_writer
  • also Socket.poll is used to double check that data can be received from or sent to the SP socket
  • if Socket.poll tells that it is not possible to receive/send data without blocking, then the hackery starts

Should nnpy support asyncio? Is API based on SocketAsync class OK?

import asyncio
import nnpy
from nnpy.constants import SNDFD, RCVFD, SOL_SOCKET
from nnpy import nanomsg, ffi

class SocketAsync(nnpy.Socket):
    def __init__(self, domain, protocol, loop=None):
        super().__init__(domain, protocol)
        if loop == None:
            loop = asyncio.get_event_loop()
        self._loop = loop

        self._reader = asyncio.Queue(loop=loop)
        self._fd_reader = None
        self._read_flags = 0

        self._writer = asyncio.Event(loop=loop)
        self._fd_writer = None
        self._write_flags = 0

    async def recv(self, flags=0):
        self._read_flags = flags
        self._enable_reader()
        value = await self._reader.get()
        return value

    async def send(self, data, flags=0):
        self._data = data
        self._write_flags = flags
        self._enable_writer()
        await self._writer.wait()

    def _notify_recv(self):
        self._loop.remove_reader(self._fd_reader)

        if self.poll(1):
            result = super().recv(self._read_flags)                                                                    
            self._reader.put_nowait(result)
        else:
            self._loop.call_later(0.5, self._enable_reader)                                                            

    def _notify_send(self):
        self._loop.remove_writer(self._fd_writer)

        if self.poll(2):
            super().send(self._data, self._write_flags)
            self._writer.set()                                                                                         
            self._writer.clear()
        else:
            self._loop.call_later(0.5, self._enable_writer)

    def _enable_reader(self):
        self._fd_reader = self.getsockopt(SOL_SOCKET, RCVFD)                                                           
        self._loop.add_reader(self._fd_reader, self._notify_recv) 

    def _enable_writer(self):                                                                                          
        self._fd_writer = self.getsockopt(SOL_SOCKET, SNDFD)                                                           
        self._loop.add_writer(self._fd_writer, self._notify_send)   

async def reader(sub):
    while True:                                                                                                        
        print('receiving...')
        value = await sub.recv()
        print('received:', value)
        await asyncio.sleep(1)

async def writer(pub):
    i = 0
    while True:
        print('sending...')
        value = '{:04}'.format(i)
        await pub.send(value)
        print('sent', value)
        i += 1
        await asyncio.sleep(0.5)


loop = asyncio.get_event_loop()

sub = SocketAsync(nnpy.AF_SP, nnpy.PULL)
sub.bind('tcp://*:5555')
pub = SocketAsync(nnpy.AF_SP, nnpy.PUSH)
pub.connect('tcp://localhost:5555')

loop.run_until_complete(asyncio.gather(writer(pub), reader(sub)))

Unable to set NN_REQ_RESEND_IVL

NN_REQ_RESEND_IVL

    This option is defined on the full REQ socket. If reply is not received in specified amount of milliseconds, the request will be automatically resent. The type of this option is int. Default value is 60000 (1 minute).

See http://nanomsg.org/v0.2/nn_reqrep.7.html

server.py

import time

import nnpy

server = nnpy.Socket(nnpy.AF_SP, nnpy.REP)
server.bind('ipc:///tmp/foo')

time.sleep(1)
print(server.recv())
#server.send('Response from server')
print(server.recv())

client.py

import nnpy

client = nnpy.Socket(nnpy.AF_SP, nnpy.REQ)
client.connect('ipc:///tmp/foo')
client.setsockopt(nnpy.SOL_SOCKET, nnpy.REQ_RESEND_IVL, 3000)

client.send('Request to server')
print(client.recv())

Steps to reproduce

$ (time python server.py &) && python client.py
b'Request to server'
b'Request to server'

real	1m0.103s
user	0m0.031s
sys	0m0.018s

protocol buffer's SerializeToString() makes UnicodeDecodeError in python 2.7.11

  File "/Users/servermanager/venv/XXXXXX/lib/python2.7/site-packages/XXX/XXX/nanoserver.py", line 68, in send
    return self.sock.send(self._send_msg.SerializeToString())
  File "/Users/servermanager/venv/XXXXXX/lib/python2.7/site-packages/nnpy/socket.py", line 53, in send
    data = data.encode() if isinstance(data, str) else data
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 3: ordinal not in range(128)

As mentioned above, when sending the string data generated by google protocol buffer, nnpy raises the UnicodeDecodeError in python 2.7

I assume that the protocol buffer serializes data and its type is 'str', however, 'str' type is 'bytes' in python 2.7. When the code meets the above line, data.encode() is called because of the data type 'str'.

However, the protocol buffer's string has many characters as a byte string over 127 so it would be NOT ascii case by case.

To use nnpy with protocol buffer, how can I handle this ?
If possible, could you please make a patch ?

pip install at windows

  1. have cmake nanomsg, and installed.

  2. add a file: site.cfg
    and input content:
    [DEFAULT]
    include_dirs = C:\Program Files (x86)\nanomsg\include
    library_dirs = C:\Program Files (x86)\nanomsg\lib
    host_library = C:\Program Files (x86)\nanomsg\bin\nanomsg.dll

  3. administrator cmd at nnpy folder, input pip install .

got error tips:
OSError: cannot load library C:\Program Files (x86)\nanomsg\bin\nanomsg.dll: error 0xc1

help...

"Getting Started" code doesn't run when building lcoally

To recreate:

Install nnpy

sudo python setup.py install

Create a new file (e.g. getting_started.py) with the code from "Getting Started"

import nnpy

pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
pub.bind('inproc://foo')

sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
sub.connect('inproc://foo')
sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

pub.send('hello, world')
print(sub.recv())

Run the file

python getting_started.py

You should see the following error

Traceback (most recent call last):
  File "getting_started.py", line 3, in <module>
    pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
AttributeError: module 'nnpy' has no attribute 'AF_SP'

Allow passing memoryview/buffers to send

As nanomsg doesn't provide multipart messages it's convenient to create a BytesIO and dump a sequence of pickles into it. That way the "parts" of the message can be recovered at the other side by means of an equivalent sequence of pickle loads.

But the current implementation of Socket.send in nnpy requires the memoryview associated with the BytesIO to be transformed to bytes first:

TypeError: initializer for ctype 'char[19]' must be a bytes or list or tuple, not memoryview

This is not efficient, as it implies an extra copy of the message. But it seems the cffi guys implemented a conversion from buffer to char array:

https://bitbucket.org/cffi/cffi/issues/65/support-memoryview-to-char-conversion
https://bitbucket.org/cffi/cffi/issues/47/creating-a-cdata-from-a-buffer

I think it's important to support this in nnpy, as nanomsg is intended to be fast and require as little copy as possible.

Is there a plan for supporting nn_recvmsg, nn_sendmsg in Socket class?

I want to implement async rep/req pattern, but there's no nn_recvmsg/nn_sendmsg supports in nnpy.

In my understanding, async rep/req needs AF_SP_RAW socket and nn_recvmsg/nn_sendmsg with nn_msghdr::msg_control field.

Do you have any plan about supporting nn_recvmsg/nn_sendmsg?

pip install . on Mac

Complete output from command python setup.py egg_info:
Traceback (most recent call last):

...
File "/Library/Python/2.7/site-packages/cffi/cparser.py", line 304, in _internal_parse
ast, macros, csource = self._parse(csource)
File "/Library/Python/2.7/site-packages/cffi/cparser.py", line 262, in _parse
self.convert_pycparser_error(e, csource)
File "/Library/Python/2.7/site-packages/cffi/cparser.py", line 291, in convert_pycparser_error
raise api.CDefError(msg)
cffi.api.CDefError: cannot parse "#endif"
:10:1: before: #

TypeError: 'NoneType' object is not iterable

hi guys,when i used pip install nnpy in Centos,i got error like "TypeError: 'NoneType' object is not iterable",details like: ( is there anyone can help me?)

Downloading/unpacking nnpy
Downloading nnpy-1.4.2.tar.gz
Running setup.py (path:/tmp/pip_build_root/nnpy/setup.py) egg_info for package nnpy
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip_build_root/nnpy/setup.py", line 3, in
setup(
File "/opt/jython/Lib/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/opt/jython/Lib/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 265, in init
self.fetch_build_eggs(attrs['setup_requires'])
File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 307, in fetch_build_eggs
resolved_dists = pkg_resources.working_set.resolve(
File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 800, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 1050, in best_match
return self.obtain(req, installer)
File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 1062, in obtain
return installer(requirement)
File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 377, in fetch_build_egg
return cmd.easy_install(req)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 629, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 659, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 844, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1072, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1058, in run_setup
run_setup(setup_script, args)
File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1058, in run_setup
run_setup(setup_script, args)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup
DirectorySandbox(setup_dir).run(runner)
File "/opt/jython/Lib/contextlib.py", line 35, in exit
self.gen.throw(type, value, traceback)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 193, in setup_context
yield
File "/opt/jython/Lib/contextlib.py", line 35, in exit
self.gen.throw(type, value, traceback)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 164, in save_modules
saved_exc.resume()
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 139, in resume
compat.reraise(type, exc, self._tb)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup
DirectorySandbox(setup_dir).run(runner)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup
DirectorySandbox(setup_dir).run(runner)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 267, in run
return func()
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 236, in runner
_execfile(setup_script, ns)
File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 46, in _execfile
exec(code, globals, locals)
File "/tmp/easy_install-5qFCQ6/cffi-1.11.4/setup.py", line 138, in
File "/tmp/easy_install-5qFCQ6/cffi-1.11.4/setup.py", line 66, in ask_supports_thread
File "/opt/jython/Lib/distutils/command/config.py", line 232, in try_compile
self._compile(body, headers, include_dirs, lang)
File "/opt/jython/Lib/distutils/command/config.py", line 232, in try_compile
self._compile(body, headers, include_dirs, lang)
File "/opt/jython/Lib/distutils/command/config.py", line 136, in _compile
(obj,) = self.compiler.object_filenames([src])
File "/opt/jython/Lib/distutils/ccompiler.py", line 871, in object_filenames
if ext not in self.src_extensions:
TypeError: 'NoneType' object is not iterable
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/tmp/pip_build_root/nnpy/setup.py", line 3, in

setup(

File "/opt/jython/Lib/distutils/core.py", line 112, in setup

_setup_distribution = dist = klass(attrs)

File "/opt/jython/Lib/distutils/core.py", line 112, in setup

_setup_distribution = dist = klass(attrs)

File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 265, in init

self.fetch_build_eggs(attrs['setup_requires'])

File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 307, in fetch_build_eggs

resolved_dists = pkg_resources.working_set.resolve(

File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 800, in resolve

dist = best[req.key] = env.best_match(req, ws, installer)

File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 1050, in best_match

return self.obtain(req, installer)

File "/opt/jython/Lib/site-packages/pkg_resources/init.py", line 1062, in obtain

return installer(requirement)

File "/opt/jython/Lib/site-packages/setuptools/dist.py", line 377, in fetch_build_egg

return cmd.easy_install(req)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 629, in easy_install

return self.install_item(spec, dist.location, tmpdir, deps)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 659, in install_item

dists = self.install_eggs(spec, download, tmpdir)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 844, in install_eggs

return self.build_and_install(setup_script, setup_base)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1072, in build_and_install

self.run_setup(setup_script, setup_base, args)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1058, in run_setup

run_setup(setup_script, args)

File "/opt/jython/Lib/site-packages/setuptools/command/easy_install.py", line 1058, in run_setup

run_setup(setup_script, args)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup

DirectorySandbox(setup_dir).run(runner)

File "/opt/jython/Lib/contextlib.py", line 35, in exit

self.gen.throw(type, value, traceback)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 193, in setup_context

yield

File "/opt/jython/Lib/contextlib.py", line 35, in exit

self.gen.throw(type, value, traceback)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 164, in save_modules

saved_exc.resume()

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 139, in resume

compat.reraise(type, exc, self._tb)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup

DirectorySandbox(setup_dir).run(runner)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 237, in run_setup

DirectorySandbox(setup_dir).run(runner)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 267, in run

return func()

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 236, in runner

_execfile(setup_script, ns)

File "/opt/jython/Lib/site-packages/setuptools/sandbox.py", line 46, in _execfile

exec(code, globals, locals)

File "/tmp/easy_install-5qFCQ6/cffi-1.11.4/setup.py", line 138, in

File "/tmp/easy_install-5qFCQ6/cffi-1.11.4/setup.py", line 66, in ask_supports_thread

File "/opt/jython/Lib/distutils/command/config.py", line 232, in try_compile

self._compile(body, headers, include_dirs, lang)

File "/opt/jython/Lib/distutils/command/config.py", line 232, in try_compile

self._compile(body, headers, include_dirs, lang)

File "/opt/jython/Lib/distutils/command/config.py", line 136, in _compile

(obj,) = self.compiler.object_filenames([src])

File "/opt/jython/Lib/distutils/ccompiler.py", line 871, in object_filenames

if ext not in self.src_extensions:

TypeError: 'NoneType' object is not iterable


Cleaning up...
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip_build_root/nnpy
Storing debug log for failure in /root/.pip/pip.log

Segfault on simple example

Consider this:

import nnpy

pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
pub.bind('inproc://foo')

sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
sub.connect('inproc://foo')
sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')

for x in xrange(3):
    pub.send('hello, world')
    print(sub.recv())

It segfaults after first loop. The segfaulting thingy is sub.recv(). publisher works ok.

Nano: 0.5
Python: pypy-2.4.0
GCC: 4.9.2

windows install

I have installed nanomsg at:
C:\Program Files (x86)\nanomsg

but when I run pip insall nnpy
or in git clone directory run python setup.py,
I got error:

WindowsError: [Error 3] : '/usr/local/include/nanomsg/.'

Install error

When trying to install nnpy via pip3 or pip, we ran into this error:

    Installed /private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/.eggs/pycparser-2.18-py3.6.egg
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/setup.py", line 28, in <module>
        install_requires=['cffi'],
      File "/usr/local/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/local/lib/python3.6/site-packages/setuptools/dist.py", line 372, in __init__
        _Distribution.__init__(self, attrs)
      File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 281, in __init__
        self.finalize_options()
      File "/usr/local/lib/python3.6/site-packages/setuptools/dist.py", line 528, in finalize_options
        ep.load()(self, ep.name, value)
      File "/private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/.eggs/cffi-1.11.5-py3.6-macosx-10.13-x86_64.egg/cffi/setuptools_ext.py", line 204, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/.eggs/cffi-1.11.5-py3.6-macosx-10.13-x86_64.egg/cffi/setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/.eggs/cffi-1.11.5-py3.6-macosx-10.13-x86_64.egg/cffi/setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "generate.py", line 120, in <module>
        ffi = create_module()
      File "generate.py", line 103, in create_module
        hfiles = header_files(set_source_args['include_dirs'])
      File "generate.py", line 28, in header_files
        return {fn: os.path.join(dir, fn) for fn in os.listdir(dir)
    FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/include/nanomsg'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3b/h9c7nf7x6_xgvy9yqb7xj8rh0000gn/T/pip-build-r14uxj7z/nnpy/

We saw issue #52, which has a similar error, except we have tried to install on macOS, Ubuntu, and Windows 10. Each time we received this same error.

Any help would be appreciated.

pipenv install fails with python3.7

env: Ubuntu 18.04

build works just fine with the built in python version 3.6.7

if I use this Pipfile:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
nnpy = "*"

[requires]
python_version = "3.7"

I get the following error:

Creating a virtualenv for this projectโ€ฆ
Pipfile: /home/sam/prj/sam/nanomsg/nnpy/Pipfile
Using /usr/bin/python3.7 (3.7.1) to create virtualenvโ€ฆ
โ น Creating virtual environment...Using base prefix '/usr'
New python executable in /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/bin/python3.7
Also creating executable in /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/bin/python
Installing setuptools, pip, wheel...
done.
Running virtualenv with interpreter /usr/bin/python3.7

โœ” Successfully created virtual environment! 
Virtualenv location: /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB
Pipfile.lock (8e2049) out of date, updating to (938715)โ€ฆ
Locking [dev-packages] dependenciesโ€ฆ
Locking [packages] dependenciesโ€ฆ
โœ” Success! 
Updated Pipfile.lock (8e2049)!
Installing dependencies from Pipfile.lock (8e2049)โ€ฆ
An error occurred while installing nnpy==1.4.2 --hash=sha256:52c1612f116294a7c87a27e49e027f3b55baefc9d279fbbf70e84d315d430ff9! Will try again.
  ๐Ÿ   โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰โ–‰ 3/3 โ€” 00:00:01
Installing initially failed dependenciesโ€ฆ
[pipenv.exceptions.InstallError]:   File "/home/sam/.local/lib/python3.6/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/home/sam/.local/lib/python3.6/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/home/sam/.local/lib/python3.6/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]:       retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]:   File "/home/sam/.local/lib/python3.6/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]:   File "/home/sam/.local/lib/python3.6/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Collecting nnpy==1.4.2 (from -r /tmp/pipenv-xtuwzjzr-requirements/pipenv-k_zvf7cp-requirement.txt (line 1))', '  Using cached https://files.pythonhosted.org/packages/23/20/490a767ad65f43e42d67766462336b8fee73fc34456ae1d15551f466332c/nnpy-1.4.2.tar.gz', 'Building wheels for collected packages: nnpy', '  Building wheel for nnpy (setup.py): started', "  Building wheel for nnpy (setup.py): finished with status 'error'", '  Running setup.py clean for nnpy', 'Failed to build nnpy', 'Installing collected packages: nnpy', '  Running setup.py install for nnpy: started', "    Running setup.py install for nnpy: finished with status 'error'"]
[pipenv.exceptions.InstallError]: ['ERROR: Complete output from command /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/bin/python3.7 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/tmp/pip-install-ye_nd0ow/nnpy/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' bdist_wheel -d /tmp/pip-wheel-rxuplbux --python-tag cp37:', '  ERROR: running bdist_wheel', '  running build', '  running build_py', '  creating build', '  creating build/lib.linux-x86_64-3.7', '  creating build/lib.linux-x86_64-3.7/nnpy', '  copying nnpy/constants.py -> build/lib.linux-x86_64-3.7/nnpy', '  copying nnpy/errors.py -> build/lib.linux-x86_64-3.7/nnpy', '  copying nnpy/tests.py -> build/lib.linux-x86_64-3.7/nnpy', '  copying nnpy/__init__.py -> build/lib.linux-x86_64-3.7/nnpy', '  copying nnpy/socket.py -> build/lib.linux-x86_64-3.7/nnpy', '  warning: build_py: byte-compiling is disabled, skipping.', '  ', '  running build_ext', "  generating cffi module 'build/temp.linux-x86_64-3.7/_nnpy.c'", '  creating build/temp.linux-x86_64-3.7', "  building '_nnpy' extension", '  creating build/temp.linux-x86_64-3.7/build', '  creating build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7', '  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/nanomsg -I/usr/local/include/nanomsg -I/usr/include/python3.7m -I/home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/include/python3.7m -c build/temp.linux-x86_64-3.7/_nnpy.c -o build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7/_nnpy.o', '  build/temp.linux-x86_64-3.7/_nnpy.c:22:12: fatal error: pyconfig.h: No such file or directory', '   #  include <pyconfig.h>', '              ^~~~~~~~~~~~', '  compilation terminated.', "  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1", '  ----------------------------------------', '  ERROR: Failed building wheel for nnpy', '    ERROR: Complete output from command /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/bin/python3.7 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/tmp/pip-install-ye_nd0ow/nnpy/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /tmp/pip-record-7f55kquw/install-record.txt --single-version-externally-managed --compile --install-headers /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/include/site/python3.7/nnpy:', '    ERROR: running install', '    running build', '    running build_py', '    creating build', '    creating build/lib.linux-x86_64-3.7', '    creating build/lib.linux-x86_64-3.7/nnpy', '    copying nnpy/constants.py -> build/lib.linux-x86_64-3.7/nnpy', '    copying nnpy/errors.py -> build/lib.linux-x86_64-3.7/nnpy', '    copying nnpy/tests.py -> build/lib.linux-x86_64-3.7/nnpy', '    copying nnpy/__init__.py -> build/lib.linux-x86_64-3.7/nnpy', '    copying nnpy/socket.py -> build/lib.linux-x86_64-3.7/nnpy', '    warning: build_py: byte-compiling is disabled, skipping.', '    ', '    running build_ext', "    generating cffi module 'build/temp.linux-x86_64-3.7/_nnpy.c'", '    creating build/temp.linux-x86_64-3.7', "    building '_nnpy' extension", '    creating build/temp.linux-x86_64-3.7/build', '    creating build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7', '    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/nanomsg -I/usr/local/include/nanomsg -I/usr/include/python3.7m -I/home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/include/python3.7m -c build/temp.linux-x86_64-3.7/_nnpy.c -o build/temp.linux-x86_64-3.7/build/temp.linux-x86_64-3.7/_nnpy.o', '    build/temp.linux-x86_64-3.7/_nnpy.c:22:12: fatal error: pyconfig.h: No such file or directory', '     #  include <pyconfig.h>', '                ^~~~~~~~~~~~', '    compilation terminated.', "    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1", '    ----------------------------------------', 'ERROR: Command "/home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/bin/python3.7 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/tmp/pip-install-ye_nd0ow/nnpy/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /tmp/pip-record-7f55kquw/install-record.txt --single-version-externally-managed --compile --install-headers /home/sam/.local/share/virtualenvs/nnpy-Zg0_5oAB/include/site/python3.7/nnpy" failed with error code 1 in /tmp/pip-install-ye_nd0ow/nnpy/']
ERROR: ERROR: Package installation failed...

Socket.sock invalid value

According to nn_socket man page, the function returns file descriptor, so Socket.sock attribute should reflect this.

If we run

import nnpy 

sub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
sub.bind('tcp://*:5555')
print(sub.sock)

The 0 will be printed.

strace gives the following in its output for above script

$ grep -e ^socket -e ^bind log           
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_IP) = 7
bind(7, {sa_family=AF_INET, sin_port=htons(5555), sin_addr=inet_addr("0.0.0.0")}, 16) = 0

So Socket.sock should be 7, not 0.

Pypi package is broken

The package seems broken :
pip install nnpy
...
Installed /tmp/pip-build-d7cwxvvy/nnpy/.eggs/pycparser-2.14-py3.4.egg
error in nnpy setup command: 'generate.py' does not name an existing file
...

From a freshly downloaded tarball :
tar -tzf /home/elbarto/nnpy-0.9.tar.gz

nnpy-0.9/
nnpy-0.9/nnpy/
nnpy-0.9/nnpy/constants.py
nnpy-0.9/nnpy/socket.py
nnpy-0.9/nnpy/init.py
nnpy-0.9/PKG-INFO
nnpy-0.9/setup.cfg
nnpy-0.9/README.rst
nnpy-0.9/setup.py
nnpy-0.9/nnpy.egg-info/
nnpy-0.9/nnpy.egg-info/PKG-INFO
nnpy-0.9/nnpy.egg-info/dependency_links.txt
nnpy-0.9/nnpy.egg-info/SOURCES.txt
nnpy-0.9/nnpy.egg-info/top_level.txt
nnpy-0.9/nnpy.egg-info/requires.txt

generate.py doesn't seems to exists.

Where can I have the error code description?

Hey fellows~I use ipc protocol do the local test and found the return value of nnpy.Socket.send executed by pub server varies from 3 to 4, while the sub client react the same and can always receive data successfully. I try to figure out the meaning of these error codes but does not know where can I found the WIKI or Documentation.
By the way, the function nnpy.Socket.setsockopt(arg0,arg1,arg3) also confuses me very much. I don't know the available value set of each communicate mode, only know that (nnpy.SUB, nnpy.SUB_SUBSCRIBE, <sub name>) and (nnpy.SUB, nnpy.RCVTIMEO,1000) works. If there is some guide can tell me how can I use setsockopt correctly?

Thanks a lot.

Use zero copy ffi.from_buffer for bytes types in `Socket.send()`

With respect to Socket.send()...

In cffi 1.8 you can use ffi.from_buffer on bytes types which provides a nice perf boost over ffi.new() when the data is large. (30% in my tests for a ~1MB buffer).

It also might also be more efficient to avoid the type checking and just assume a from_buffer type will be used (fast path) and do any conversion to a bytes type in an exception handler (slow path).

I've not tested on python2 nor do I understand the ramifications of such a change to that platform.

IPC PUB-SUB protocol doesn't work

Trying to test with IPC protocol, but messages are never received:

publisher:

>>> import nnpy
>>> pub = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
>>> pub.bind('ipc://qwer')
1
>>> pub.send('wazup')

subscriber:

>>> import nnpy
>>> sub = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
>>> sub.connect('ipc://qwer')
1
>>> sub.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, '')
>>> sub.recv()

Is there anything Python-specific for IPC I'm missing out here? I tried nanomsg-python - it doesn't work either.

Tag fixed tests

Could someone tag 98ee46a as 1.4.2 ?

It would be nice to have version for python3 with proper test

PULL binded Socket does not work in a Python process

I tried to use nnpy 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.
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 nnpy 

    class ServerSocket(multiprocessing.Process):

    def __init__(self, server):
        super(ServerSocket, self).__init__()
        self.daemon = True
        self.server=server

    def on_receive(self, msg):
        pass

    def run(self):
        self.socket = nnpy.Socket(nnpy.AF_SP, nnpy.PULL)
        self.socket.setsockopt(nnpy.SOL_SOCKET, nnpy.SOCKET_NAME, "ServerSocket")       
        self.socket.bind(self.server)
        while True:
            msg=self.socket.recv()
            self.on_receive(msg)
        self.socket.close()

I obtained the same behavior with python-nanomsg.

Socket already connected error quits python interpreter

A survivable annoyance, but I figured I'd report it anyway as this is a fantastic library.

To reproduce:

sock = nnpy.Socket(nnpy.AF_SP, nnpy.PAIR)
sock.bind('inproc://pair')
s1 = nnpy.Socket(nnpy.AF_SP, nnpy.PAIR)
s1.connect('inproc://pair')
s2 = nnpy.Socket(nnpy.AF_SP, nnpy.PAIR)
s2.connect('inproc://pair')
0   libnanomsg.5.0.0.dylib              0x0000000103cbbf8c nn_sinproc_handler + 1279
1   libnanomsg.5.0.0.dylib              0x0000000103cad227 nn_ctx_leave + 164
2   libnanomsg.5.0.0.dylib              0x0000000103cad234 nn_ctx_leave + 177
3   libnanomsg.5.0.0.dylib              0x0000000103cad234 nn_ctx_leave + 177
4   libnanomsg.5.0.0.dylib              0x0000000103cac441 nn_sock_add_ep + 163
5   libnanomsg.5.0.0.dylib              0x0000000103ca9ed2 nn_connect + 72
6   _nnpy.cpython-35m-darwin.so         0x0000000103ca15db _cffi_f_nn_connect + 203
7   python3.5                           0x0000000101e12f6c PyCFunction_Call + 220
8   python3.5                           0x0000000101e8bd4d PyEval_EvalFrameEx + 23901
9   python3.5                           0x0000000101e909e0 fast_function + 288
10  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
11  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
12  python3.5                           0x0000000101e85f71 PyEval_EvalCode + 81
13  python3.5                           0x0000000101e83806 builtin_exec + 534
14  python3.5                           0x0000000101e12f6c PyCFunction_Call + 220
15  python3.5                           0x0000000101e8bd4d PyEval_EvalFrameEx + 23901
16  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
17  python3.5                           0x0000000101e90a62 fast_function + 418
18  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
19  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
20  python3.5                           0x0000000101e90a62 fast_function + 418
21  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
22  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
23  python3.5                           0x0000000101e90a62 fast_function + 418
24  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
25  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
26  python3.5                           0x0000000101e90a62 fast_function + 418
27  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
28  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
29  python3.5                           0x0000000101e90a62 fast_function + 418
30  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
31  python3.5                           0x0000000101e909e0 fast_function + 288
32  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
33  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
34  python3.5                           0x0000000101e85fce PyEval_EvalCodeEx + 78
35  python3.5                           0x0000000101df5620 function_call + 384
36  python3.5                           0x0000000101dce171 PyObject_Call + 97
37  python3.5                           0x0000000101e8c50b PyEval_EvalFrameEx + 25883
38  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
39  python3.5                           0x0000000101e90a62 fast_function + 418
40  python3.5                           0x0000000101e8bbca PyEval_EvalFrameEx + 23514
41  python3.5                           0x0000000101e9021b _PyEval_EvalCodeWithName + 3227
42  python3.5                           0x0000000101e85f71 PyEval_EvalCode + 81
43  python3.5                           0x0000000101eb5fd1 PyRun_FileExFlags + 209
44  python3.5                           0x0000000101eb5605 PyRun_SimpleFileExFlags + 469
45  python3.5                           0x0000000101ecdd54 Py_Main + 3348
46  python3.5                           0x0000000101dc384d main + 237
47  libdyld.dylib                       0x00007fff986d25ad start + 1
Socket is already connected [56] (/tmp/nanomsg-20160616-98477-1e3t8g0/nanomsg-1.0.0/src/transports/inproc/sinproc.c:392)
fish: 'ipython' terminated by signal SIGABRT (Abort)

Python version 3.5.1 (using pyenv on OSX El Capitan)

nnpy-win error

Hi
Hope my question is addressed to the correct forum,,, this is the "closest" one I found

On a HyperV server I have a Windows 10 client running.
I have installed nanomsg for 64 bit system.

then I followed this steps:

> git clone https://github.com/neutrinoyu/nnpy-win.git
> mv nnpy-wi  nnpy
> cd nnpy
>  python3 -m pip install .

This caused the following error:

Processing c:\program files\nnpy
    Complete output from command python setup.py egg_info:
    warning: no previously-included files found matching 'setup.pyc'
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
    zip_safe flag not set; analyzing archive contents...
    pycparser.ply.__pycache__.lex.cpython-37: module references __file__
    pycparser.ply.__pycache__.lex.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module references __file__
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-37: module MAY be using inspect.stack
    pycparser.ply.__pycache__.ygen.cpython-37: module references __file__

    Installed c:\users\lars-g~1\appdata\local\temp\pip-req-build-vsvub3fh\.eggs\pycparser-2.19-py3.7.egg
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\LARS-G~1\AppData\Local\Temp\pip-req-build-vsvub3fh\setup.py", line 28, in <module>
        install_requires=['cffi'],
      File "C:\Program Files\Python37\lib\site-packages\setuptools\__init__.py", line 143, in setup
        return distutils.core.setup(**attrs)
      File "C:\Program Files\Python37\lib\distutils\core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "C:\Program Files\Python37\lib\site-packages\setuptools\dist.py", line 442, in __init__
        k: v for k, v in attrs.items()
      File "C:\Program Files\Python37\lib\distutils\dist.py", line 292, in __init__
        self.finalize_options()
      File "C:\Program Files\Python37\lib\site-packages\setuptools\dist.py", line 601, in finalize_options
        ep.load()(self, ep.name, value)
      File "c:\users\lars-g~1\appdata\local\temp\pip-req-build-vsvub3fh\.eggs\cffi-1.11.5-py3.7-win-amd64.egg\cffi\setuptools_ext.py", line 204, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "c:\users\lars-g~1\appdata\local\temp\pip-req-build-vsvub3fh\.eggs\cffi-1.11.5-py3.7-win-amd64.egg\cffi\setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "c:\users\lars-g~1\appdata\local\temp\pip-req-build-vsvub3fh\.eggs\cffi-1.11.5-py3.7-win-amd64.egg\cffi\setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "generate.py", line 133, in <module>
        ffi = create_module()
      File "generate.py", line 126, in create_module
        library_dirs = [DEFAULT_LIBRARY_DIR], libraries=['nanomsg'], **set_source_args)
    TypeError: set_source() got multiple values for keyword argument 'library_dirs'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\LARS-G~1\AppData\Local\Temp\pip-req-build-vsvub3fh\

Can anyone help me to understand ??

`site_cfg` is not defined

When I tried to use CPATH environment variable to pass include dierctory, I got this:

  File "generate.py", line 99, in create_module
    site_cfg['include_dirs'] += [os.path.join(p, 'nanomsg')
NameError: global name 'site_cfg' is not defined

The reason is this line. It should probably be set_source_args instead of site_cfg

OSError: cannot load library libnanomsg.so.5.0.0

nnpy install fails with the following traceback

$ sudo pip install nnpy
Downloading/unpacking nnpy
  Downloading nnpy-1.3.tar.gz
  Running setup.py (path:/tmp/pip_build_root/nnpy/setup.py) egg_info for package nnpy
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/nnpy/setup.py", line 28, in <module>
        install_requires=['cffi'],
      File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 318, in __init__
        _Distribution.__init__(self, attrs)
      File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
        self.finalize_options()
      File "/usr/local/lib/python2.7/dist-packages/setuptools/dist.py", line 376, in finalize_options
        ep.load()(self, ep.name, value)
      File "/usr/local/lib/python2.7/dist-packages/cffi/setuptools_ext.py", line 187, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/usr/local/lib/python2.7/dist-packages/cffi/setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/usr/local/lib/python2.7/dist-packages/cffi/setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "generate.py", line 119, in <module>
        ffi = create_module()
      File "generate.py", line 115, in create_module
        f.write(symbols(ffi, host_library))
      File "generate.py", line 56, in symbols
        nanomsg = ffi.dlopen(host_library)
      File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 139, in dlopen
        lib, function_cache = _make_ffi_library(self, name, flags)
      File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 769, in _make_ffi_library
        backendlib = _load_backend_lib(backend, libname, flags)
      File "/usr/local/lib/python2.7/dist-packages/cffi/api.py", line 764, in _load_backend_lib
        return backend.load_library(path, flags)
    OSError: cannot load library libnanomsg.so.5.0.0: libnanomsg.so.5.0.0: cannot open shared object file: No such file or directory

nanomsg is installed in /usr/local/lib/x86_64-linux-gnu/:

$ ls -la /usr/local/lib/x86_64-linux-gnu/
total 400
drwxr-xr-x 3 root root   4096 Nov  7 20:29 .
drwxr-xr-x 6 root root   4096 Nov  4 13:53 ..
lrwxrwxrwx 1 root root     19 Nov  4 13:53 libnanomsg.so -> libnanomsg.so.5.0.0
-rw-r--r-- 1 root root 395509 Nov  7 20:28 libnanomsg.so.1.0.0
lrwxrwxrwx 1 root root     19 Nov  4 13:53 libnanomsg.so.5.0.0 -> libnanomsg.so.1.0.0
drwxr-xr-x 2 root root   4096 Nov  7 20:29 pkgconfig

LD_LIBRARY_PATH points to that location (I also have https://github.com/tonysimpson/nanomsg-python installed and previously it failed to install without this env var):

export LD_LIBRARY_PATH=/usr/local/lib/x86_64-linux-gnu/

Code fails on the line https://github.com/nanomsg/nnpy/blob/1.3/generate.py#L56, I tried to dig a bit deeper, it seems like shared library is found by ctypes.util.find_library but fails to load.

$ sudo python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes.util
>>> ctypes.util.find_library('nanomsg')
'libnanomsg.so.5.0.0'
$ sudo pip freeze | grep cffi 
cffi==1.9.1

I also tried with cffi==1.8.3 - same issue.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

Any idea how to fix this?

Subscribe to subprocess not receiving with multiple nnpy channels

Problem

When I have two nnpy.Sockets, a REQ socket in the main thread, and a SUB socket created later in a multiprocessing.Process, the SUB socket never receives anything. This problem does not occur for:

  • Single SUB socket in a multiprocessing.Process.
  • SUB and REQ sockets both in the main thread.
  • SUB socket in a threading.Thread and REQ socket in the main thread (but I have no choice but to use multiprocessing.Process for other reasons)

Minimal Example

main.py

import nnpy
import multiprocessing

cmd_socket = nnpy.Socket(nnpy.AF_SP, nnpy.REQ)
cmd_socket.bind("ipc:///tmp/nnpy-test-cmd")

cmd_socket.send("start")
assert cmd_socket.recv() == "Starting!"

def run_sub():
    sub_socket = nnpy.Socket(nnpy.AF_SP, nnpy.SUB)
    sub_socket.setsockopt(nnpy.SUB, nnpy.SUB_SUBSCRIBE, "topic:")
    sub_socket.connect("ipc:///tmp/nnpy-test-pub")

    while True:
        print "received " + repr(sub_socket.recv())

sub = multiprocessing.Process(target=run_sub)
sub.daemon = True
sub.start()
sub.join()

child.py

import nnpy
import time

cmd_socket = nnpy.Socket(nnpy.AF_SP, nnpy.REP)
cmd_socket.connect("ipc:///tmp/nnpy-test-cmd")

assert 'start' == cmd_socket.recv()

pub_socket = nnpy.Socket(nnpy.AF_SP, nnpy.PUB)
pub_socket.bind("ipc:///tmp/nnpy-test-pub")

cmd_socket.send("Starting!")

for n in range(10):
    pub_socket.send("topic:It is now " + str(time.time()) + " o'clock!")
    time.sleep(0.25)

This code works if we either remove the 'start' 'Starting!' request/response, or run run_sub in the main thread or a threading.Thread instead of in a multiprocessing.Process.

Here are test cases with more print statements that show the cases where this works and does not work.

The problem is definitely on the receiving end, as the SUB/PUB socket can be subscribed to and receives the messages in other programs.

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.