Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pip install for python3, command argument and connection issue #11

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
sys.exit()

# http://stackoverflow.com/questions/14399534/how-can-i-reference-requirements-txt-for-the-install-requires-kwarg-in-setuptool
install_reqs = parse_requirements('requirements.txt', session=PipSession())
req_list = [str(ir.req) for ir in install_reqs]
#install_reqs = parse_requirements('requirements.txt', session=PipSession())
#req_list = [str(ir.req) for ir in install_reqs]

readme = open('README.rst').read()
# doclink = """
Expand All @@ -42,7 +42,13 @@
packages=find_packages(exclude=['test*']),
package_dir={'wabbit_wappa': 'wabbit_wappa'},
include_package_data=True,
install_requires=req_list,
install_requires=[
'pexpect',
'pytest',
'cookiecutter',
'wheel>=0.22',
'pip>=1.4',
],
license='MIT',
keywords='wabbit_wappa',
classifiers=[
Expand Down
10 changes: 9 additions & 1 deletion wabbit_wappa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function, division, absolute_import, unicode_literals
from time import sleep

"""
Wrapper for Vowpal Wabbit executable
Expand Down Expand Up @@ -241,7 +242,12 @@ def __init__(self, command=None, active_mode=False, dummy_mode=False, **kwargs):
if active_mode:
self.vw_process = active_learner.ActiveVWProcess(command, port=port)
else:
self.vw_process = pexpect.spawn(command)
# Run VW in shell with 'canonical mode processing' disabled
# See: http://pexpect.readthedocs.org/en/stable/api/pexpect.html#pexpect.spawn.send
self.vw_process = pexpect.spawn('/bin/bash')
self.vw_process.sendline('stty -icanon')
self.vw_process.sendline(command)

# Turn off delaybeforesend; this is necessary only in non-applicable cases
self.vw_process.delaybeforesend = 0
self.vw_process.setecho(False)
Expand Down Expand Up @@ -386,6 +392,8 @@ def save_model(self, model_filename):
# No response is expected in this case

def close(self):
"""Sleep a bit to let VW finish saving model"""
sleep(2)
"""Shut down the VW process."""
self.vw_process.close()
# TODO: Give this a context manager interface
Expand Down
3 changes: 2 additions & 1 deletion wabbit_wappa/active_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


def get_active_default_settings():
result = dict(active_learning=True,
result = dict(active=True,
port=DEFAULT_PORT,
predictions='/dev/null',
)
Expand All @@ -45,6 +45,7 @@ def __init__(self, command, port=DEFAULT_PORT):
# Launch the VW process, which we will communicate with only
# via its socket
self.vw_process = pexpect.spawn(command)
time.sleep(5) #the spawned process is not instantly ready for connections
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection_tries = 0
while connection_tries < MAX_CONNECTION_ATTEMPTS:
Expand Down