IMP  2.0.0
The Integrative Modeling Platform
PyroHandlerLoader.py
1 ##
2 ## The Inferential Structure Determination (ISD) software library
3 ##
4 ## Authors: Darima Lamazhapova and Wolfgang Rieping
5 ##
6 ## Copyright (C) Michael Habeck, Wolfgang Rieping
7 ##
8 ## All rights reserved.
9 ##
10 ## NO WARRANTY. This library is provided 'as is' without warranty of any
11 ## kind, expressed or implied, including, but not limited to the implied
12 ## warranties of merchantability and fitness for a particular purpose or
13 ## a warranty of non-infringement.
14 ##
15 ## Distribution of substantively modified versions of this module is
16 ## prohibited without the explicit permission of the copyright holders.
17 ##
18 
19 __doc__ = """This script must be launched on the host where a calculation
20 is sought to be made; It forks a thread that runs the pyro handler.
21 
22 Arguments (in order):
23  niceness (int)
24  nameserver's hostname (string, or None to broadcast for it)
25  uri of this instance's PyroHandler (string)
26  timeout (int)
27  debug token (bool)
28  display X11 window (bool)
29  temp path (string)
30 """
31 
32 if __name__ == '__main__':
33 
34  import os, sys, socket
35  from threading import Thread
36  from IMP.isd.PyroGrid import PyroHandler
37  from IMP.isd.PyroUtils import launch_instance #, get_proxy
38 
39 
40  # niceness = 19
41  # nshost = 'horse--bio'
42  # obj_name = 'PyroHandler.0'
43  # debug = True
44 
45  #Profile=False
46  #if Profile:
47  # import yappi
48  # yappi.start()
49 
50  niceness = eval(sys.argv[1])
51  try:
52  nshost = eval(sys.argv[2])
53  except:
54  nshost = sys.argv[2]
55 
56  uri = sys.argv[3]
57  timeout = eval(sys.argv[4])
58  debug = eval(sys.argv[5])
59  display = eval(sys.argv[6])
60  temp_path = sys.argv[7]
61 
62  os.environ['ISD_ROOT'] = temp_path
63 
64  if not temp_path in sys.path:
65  sys.path.insert(0, temp_path)
66 
67  os.nice(niceness)
68 
69  print 'PyroHandlerLoader: %s (%s)' % (uri, socket.gethostname())
70 
71  #following command also forks a WatchDog thread via PyroHandler.__init__
72  handler_instance = PyroHandler(timeout, nshost, debug)
73 
74  print 'PyroHandlerLoader: starting launch_instance in a thread'
75 
76  #the delegate approach is not used since PyroHandler is inherited from Pyro.core.ObjBase
77  t = Thread(target = launch_instance, \
78  args = (handler_instance, uri, False, \
79  nshost, debug, not display))
80  t.start()
81 
82  print 'PyroHandlerLoader: thread has been launched'
83 
84  ## get_proxy: initializes Pyro client on server side
85 
86  ## handler = get_proxy(uri, nshost)
87  ## print 'handler = \nPyroUtils.get_proxy\n(\'%s\',\n \'%s\')\n' % (uri, nshost)
88 
89 
90  #if Profile:
91  # import time
92  # fl=open("/Bis/home/yannick/simulations/test_isd_ww/profiled_"+str(int(time.time())),'w')
93  # for stat in yappi.get_stats(): fl.write(stat+"\n")
94  # fl.close()
95  # yappi.stop()