Skip to content

Commit 6c7e2fb

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents 1cf9ae9 + a07132e commit 6c7e2fb

6 files changed

Lines changed: 155 additions & 130 deletions

File tree

doc/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Installation of **psiTurk** requires:
2727
4. **A web browser.** A WebKit compatible browser such as FireFox,
2828
Safari, or Chrome is recommended.
2929

30-
An addition requirement for actually using **psiTurk** to run experiments
30+
An additional requirement for actually using **psiTurk** to run experiments
3131
is a Internet connected computer capable of receiving incoming requests.
3232

3333
Installation steps

psiturk/amt_services.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def verify_aws_login(self):
130130
print exception.error_message
131131
return False
132132
except AttributeError:
133-
print "*** Unable to establish connection to AWS region %s \
134-
using your access key/secret key", self.region
133+
print "*** Unable to establish connection to AWS region %s "\
134+
"using your access key/secret key", self.region
135135
return False
136136
except boto.exception.BotoServerError:
137137
print "***********************************************************"
@@ -151,8 +151,8 @@ def verify_aws_login(self):
151151
def connect_to_aws_rds(self):
152152
''' Connec to aws rds '''
153153
if not self.valid_login:
154-
print 'Sorry, unable to connect to Amazon\'s RDS database server. \
155-
AWS credentials invalid.'
154+
print 'Sorry, unable to connect to Amazon\'s RDS database server. "\
155+
"AWS credentials invalid.'
156156
return False
157157
# rdsparams = dict(
158158
# aws_access_key_id = self.aws_access_key_id,
@@ -307,8 +307,8 @@ def __init__(self, aws_access_key_id, aws_secret_access_key, is_sandbox):
307307
if not self.valid_login:
308308
print 'WARNING *****************************'
309309
print 'Sorry, AWS Credentials invalid.\nYou will only be able to '\
310-
+ 'test experiments locally until you enter\nvalid '\
311-
+ 'credentials in the AWS Access section of ~/.psiturkconfig\n'
310+
'test experiments locally until you enter\nvalid '\
311+
'credentials in the AWS Access section of ~/.psiturkconfig\n'
312312

313313
def update_credentials(self, aws_access_key_id, aws_secret_access_key):
314314
''' Update credentials '''
@@ -482,8 +482,8 @@ def verify_aws_login(self):
482482
def connect_to_turk(self):
483483
''' Connect to turk '''
484484
if not self.valid_login:
485-
print 'Sorry, unable to connect to Amazon Mechanical Turk. AWS \
486-
credentials invalid.'
485+
print 'Sorry, unable to connect to Amazon Mechanical Turk. AWS '\
486+
'credentials invalid.'
487487
return False
488488
if self.is_sandbox:
489489
host = 'mechanicalturk.sandbox.amazonaws.com'
@@ -571,8 +571,8 @@ def dispose_hit(self, hitid):
571571
try:
572572
self.mtc.dispose_hit(hitid)
573573
except Exception, e:
574-
print 'Failed to dispose of HIT %s. Make sure there are no \
575-
assignments remaining to be reviewed' % hitid
574+
print 'Failed to dispose of HIT %s. Make sure there are no "\
575+
"assignments remaining to be reviewed' % hitid
576576

577577
def extend_hit(self, hitid, assignments_increment=None,
578578
expiration_increment=None):

psiturk/experiment_server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from psiturk_config import PsiturkConfig
66
import sys
77
import setproctitle
8+
import os
89

910
config = PsiturkConfig()
1011
config.load_config()
@@ -24,7 +25,11 @@ def __init__(self):
2425
self.options = self.user_options
2526
self.prog = None
2627
self.do_load_config()
27-
print "Now serving on", "http://" + self.options["bind"]
28+
if 'OPENSHIFT_SECRET_TOKEN' in os.environ:
29+
my_ip = os.environ['OPENSHIFT_APP_DNS']
30+
print "Now serving on " + os.environ['OPENSHIFT_APP_DNS']
31+
else:
32+
print "Now serving on", "http://" + self.options["bind"]
2833

2934
def init(self, *args):
3035
'''init method

psiturk/experiment_server_controller.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import urllib2
77
import socket
88
import psutil
9+
import time
910

1011

1112
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -118,21 +119,35 @@ def shutdown(self, ppid=None):
118119
else:
119120
self.server_running = False
120121

122+
def kill_child_processes(self, parent_pid, sig=signal.SIGTERM):
123+
if os.uname()[0] is 'Linux':
124+
ps_command = subprocess.Popen('pstree -p %d | perl -ne \'print "$1 "\
125+
while /\((\d+)\)/g\'' % parent.pid,
126+
shell=True, stdout=subprocess.PIPE)
127+
ps_output = ps_command.stdout.read()
128+
retcode = ps_command.wait()
129+
assert retcode == 0, "ps command returned %d" % retcode
130+
for pid_str in ps_output.split("\n")[:-1]:
131+
os.kill(int(pid_str), sig)
132+
if os.uname()[0] is 'Darwin':
133+
child_pid = parent.get_children(recursive=True)
134+
for pid in child_pid:
135+
pid.send_signal(signal.SIGTERM)
136+
121137
def is_server_running(self):
122138
PROCNAME = "psiturk_experiment_server"
123139
cmd = "ps -eo pid,command | grep '"+ PROCNAME + "' | grep -v grep | awk '{print $1}'"
124140
psiturk_exp_processes = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
125141
output = psiturk_exp_processes.stdout.readlines()
126-
psiturk_exp_ports = [process[0].laddr[1] for process in [psutil.Process(int(pid)).get_connections() for pid in output]]
127-
p = psutil.Process(psiturk_exp_processes.pid)
128-
child_pid = p.get_children(recursive=True)
129-
for pid in child_pid:
130-
pid.send_signal(signal.SIGTERM)
142+
psiturk_exp_ports = []
143+
if output:
144+
psiturk_exp_ports = [process[0].laddr[1] for process in [psutil.Process(int(pid)).get_connections() for pid in output]]
145+
parent = psutil.Process(psiturk_exp_processes.pid)
146+
self.kill_child_processes(parent.pid)
131147
if psiturk_exp_ports:
132148
is_psiturk_using_port = True
133149
else:
134150
is_psiturk_using_port = False
135-
136151
is_port_open = self.is_port_available()
137152
#print self.server_running, " ", portopen
138153
if is_port_open and is_psiturk_using_port: # This should never occur
@@ -164,4 +179,5 @@ def startup(self):
164179
print "Experiment server may be already running..."
165180
elif server_status == 'blocked':
166181
print "Another process is running on the desired port. Try using a different port number."
182+
time.sleep(1.2) # Allow CLI to catch up.
167183

psiturk/psiturk_org_services.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,24 @@ def __init__(self):
249249
self.access_key = config.get('psiTurk Access', 'psiturk_access_key_id')
250250
self.secret_key = config.get('psiTurk Access', 'psiturk_secret_access_id')
251251
self.local_port = config.getint('Server Parameters', 'port')
252-
self.check_os()
252+
self.is_open = False
253253
self.tunnel_port = 8000 # Set by tunnel server
254254
self.tunnel_host = 'tunnel.psiturk.org'
255255
self.tunnel_server = os.path.join(os.path.dirname(__file__),
256256
"tunnel/ngrok")
257257
self.tunnel_config = os.path.join(os.path.dirname(__file__),
258258
"tunnel/ngrok-config")
259-
self.is_open = False
260259

261260
@classmethod
262-
def check_os(cls):
261+
def is_compatible(cls):
263262
''' Check OS '''
264263
is_64bit = struct.calcsize('P')*8 == 64
265-
if (_platform == "linux" or _platform == "linux2" or "win32" or not
266-
is_64bit):
267-
Exception('Your OS is currently unsupported.')
264+
if (_platform == "darwin" and is_64bit):
265+
return True
266+
else:
267+
print("Linux tunnels are currenlty unsupported. Please notify "\
268+
"authors@psiturk.org\nif you'd like to see this feature.")
269+
return False
268270

269271
def get_tunnel_ad_url(self):
270272
''' Get tunnel hostname from psiturk.org '''
@@ -290,17 +292,20 @@ def change_tunnel_ad_url(self):
290292

291293
def open(self):
292294
''' Open tunnel '''
293-
tunnel_ad_url = self.get_tunnel_ad_url()
294-
if not tunnel_ad_url:
295-
return("Tunnel server appears to be down.")
296-
cmd = '%s -subdomain=%s -config=%s -log=stdout %s 2>&1 > server.log' \
297-
%(self.tunnel_server, tunnel_ad_url, self.tunnel_config,
298-
self.local_port)
299-
self.tunnel = subprocess.Popen(cmd, shell=True)
300-
self.url = '%s.%s' %(tunnel_ad_url, self.tunnel_host)
301-
self.full_url = 'http://%s.%s:%s' %(tunnel_ad_url, self.tunnel_host,
302-
self.tunnel_port)
303-
self.is_open = True
295+
if self.is_compatible():
296+
tunnel_ad_url = self.get_tunnel_ad_url()
297+
if not tunnel_ad_url:
298+
return("Tunnel server appears to be down.")
299+
cmd = '%s -subdomain=%s -config=%s -log=stdout %s 2>&1 > server.log' \
300+
%(self.tunnel_server, tunnel_ad_url, self.tunnel_config,
301+
self.local_port)
302+
self.tunnel = subprocess.Popen(cmd, shell=True)
303+
self.url = '%s.%s' %(tunnel_ad_url, self.tunnel_host)
304+
self.full_url = 'http://%s.%s:%s' %(tunnel_ad_url, self.tunnel_host,
305+
self.tunnel_port)
306+
self.is_open = True
307+
print "Tunnel URL: %s" % self.full_url
308+
print "Hint: In OSX, you can open a terminal link using cmd + click"
304309

305310
def close(self):
306311
''' Close tunnel '''

0 commit comments

Comments
 (0)