Package Biskit :: Package PVM :: Module ExampleSlave
[hide private]
[frames] | no frames]

Source Code for Module Biskit.PVM.ExampleSlave

 1  ## 
 2  ## Biskit, a toolkit for the manipulation of macromolecular structures 
 3  ## Copyright (C) 2004-2005 Raik Gruenberg & Johan Leckner 
 4  ## 
 5  ## This program is free software; you can redistribute it and/or 
 6  ## modify it under the terms of the GNU General Public License as 
 7  ## published by the Free Software Foundation; either version 2 of the 
 8  ## License, or any later version. 
 9  ## 
10  ## This program is distributed in the hope that it will be useful, 
11  ## but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
13  ## General Public License for more details. 
14  ## 
15  ## You find a copy of the GNU General Public License in the file 
16  ## license.txt along with this program; if not, write to the Free 
17  ## Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
18  ## 
19  ## 
20  ## $Revision: 2.3 $ 
21  ## last $Date: 2006/12/22 14:27:30 $ 
22  ## last $Author: graik $ 
23   
24  """ 
25  An example of a Slave/Master setup. 
26  """ 
27   
28  from Biskit.PVM import JobSlave 
29  import Biskit.tools as T 
30  import subprocess 
31   
32  import time 
33   
34 -class Slave(JobSlave):
35
36 - def initialize(self, params):
37 """ 38 Parameters handed over by master. 39 """ 40 self.params = params
41 ## or perhaps easier: 42 ## self.__dict__.update( params ) 43 44
45 - def go(self, dict):
46 """ 47 Perform slave task. 48 """ 49 d = {} 50 51 T.flushPrint( self.params['progress_str'] ) 52 for id, val in dict.items(): 53 54 d[id] = val+1 55 56 for i in range(1, 1000): 57 f = 1.0 * i / 1200232112312.11 58 59 T.flushPrint( str(id) + ' ' ) 60 time.sleep(0.5) 61 62 print "Done." 63 return d
64 65 66 if __name__ == '__main__': 67 68 import os, sys 69 70 if len(sys.argv) == 2: 71 72 niceness = int(sys.argv[1]) 73 os.nice(niceness) 74 75 slave = Slave() 76 slave.start() 77