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

Added windows compatability for hyperopt-mongo-worker #452

Merged
merged 1 commit into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions hyperopt/mongoexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,11 +1188,12 @@ def sighandler_shutdown(signum, frame):
def sighandler_wait_quit(signum, frame):
logger.info('Caught signal %i, shutting down.' % signum)
raise WaitQuit(signum)

is_windows = os.name == 'nt'
if not is_windows:
signal.signal(signal.SIGHUP, sighandler_shutdown)
signal.signal(signal.SIGUSR1, sighandler_wait_quit)
signal.signal(signal.SIGINT, sighandler_shutdown)
signal.signal(signal.SIGHUP, sighandler_shutdown)
signal.signal(signal.SIGTERM, sighandler_shutdown)
signal.signal(signal.SIGUSR1, sighandler_wait_quit)

if N > 1:
proc = None
Expand Down Expand Up @@ -1226,7 +1227,7 @@ def sighandler_wait_quit(signum, frame):
# this is the normal way to stop the infinite loop (if originally N=-1)
if proc:
# proc.terminate() is only available as of 2.6
os.kill(proc.pid, signal.SIGTERM)
os.kill(proc.pid, signal.CTRL_C_EVENT if is_windows else signal.SIGTERM)
return proc.wait()
else:
return 0
Expand Down Expand Up @@ -1261,6 +1262,9 @@ def sighandler_wait_quit(signum, frame):
else:
raise ValueError("N <= 0")

def main():
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
sys.exit(main_worker())

def main_worker():
parser = optparse.OptionParser(usage="%prog [options]")
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,16 @@ def find_package_data(packages):
if package_data is None:
package_data = find_package_data(packages)

if scripts is None:
scripts = find_scripts()

setuptools.setup(
name=package_name,
version='0.1.1',
packages=packages,
scripts=scripts,
entry_points={
'console_scripts': [
'hyperopt-mongo-worker=hyperopt.mongoexp:main'
],
},
url='http://hyperopt.github.com/hyperopt/',
author='James Bergstra',
author_email='james.bergstra@gmail.com',
Expand Down