Changes between Version 9 and Version 10 of PythonApps


Ignore:
Timestamp:
Aug 13, 2009, 2:32:17 PM (15 years ago)
Author:
davea
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PythonApps

    v9 v10  
    33Python applications can be run two different ways: by using the [http://pymw.sourceforge.net/ PyMW framework] (cross platform) or by using [http://www.py2exe.org/ py2exe] (Windows only). Both methods are discussed here.
    44
    5 == Using PyMW ==
    6 The [http://pymw.sourceforge.net/ PyMW framework] is a master-worker computing framework for Python. Using PyMW in conjunction with a special interpreter (PyBOINC) allows you to send Python scripts as work units and does not require the client to have Python installed. PyMW can also be used without the portable Python interpreter, however, the client is responsible for installing the correct version of Python (2.4 or greater) and adding the interpreter to their system PATH environment variable.
    75
    8 In addition to BOINC, PyMW also provides non-BOINC interfaces for Condor, MPI, and simple multi-core processing which can be selected using a command line switch. The multi-core interface is particularly useful for debugging BOINC applications before submitting them to your project.
    9 
    10 The following is a brief explanation of how to setup PyMW using the [VmServer BOINC virtual server].
    11 
    12 === Installing and Testing PyMW ===
    13 Before starting this tutorial you should setup the [VmServer BOINC virtual server] following the instructions in the [QuickStart Quick Start] guide. It's also highly recommended that you ssh into your VM instead of using a VM viewer so that you can copy and paste commands. You can start the ssh daemon with the following command:
    14 
    15 {{{
    16  $ su -c "/usr/sbin/sshd"
    17 }}}
    18 
    19 Once your server is setup, login to your VM as "boincadm" (with password "boincadmpw" if you haven't changed it). To install PyMW, first download the PyMW package and unzip it into your home folder on the BOINC VM and run the setup script to install it into your local Python "site-packages" directory. This can be done with the following commmands:
    20 
    21 {{{
    22 $ cd ~
    23 $ wget http://downloads.sourceforge.net/project/pymw/pymw/PyMW%200.2/pymw-0.2.tar.gz
    24 $ tar -xzf pymw-0.2.tar.gz
    25 $ rm pymw-0.2.tar.gz
    26 $ cd pymw-0.2
    27 $ su -c "python setup.py install"
    28 
    29 (the password for root is rootpw, unless you changed it)
    30 }}}
    31 
    32 ''Note that the URL for PyMW was current as of the time of this writing (v0.2), but you should check for and use the newest available release.''
    33 
    34 At this point, PyMW is installed and so it's a good idea to test the installation. While still in the PyMW directory that you extracted above, try the following example distributed with PyMW:
    35 
    36 {{{
    37 $ cd examples
    38 $ python monte_pi.py
    39 
    40 (some output should appear)
    41 
    42 $ cd ../../
    43 }}}
    44 
    45 After a moment, you should see some vague estimate of PI printed out to the screen. This means that PyMW is installed and working properly. By default, the example that was run above uses the "generic" interface and does not interact with the BOINC server.
    46 
    47 Next, you should install PyBOINC to allow your PyMW apps to run without Python being installed on the BOINC client's machines. The following downloads the zip file, extracts it and moves it into a convenient location:
    48 
    49 {{{
    50 $ wget http://bitbucket.org/jeremycowles/pyboinc/downloads/pyboinc-0.01.zip
    51 $ unzip pyboinc-0.01.zip
    52 $ mv pyboinc-0.01/bin-python26 pyboinc
    53 $ rm -r pyboinc-0.01
    54 $ rm pyboinc-0.01.zip
    55 }}}
    56 
    57 With PyMW and PyBOINC setup, it's time to run a real BOINC application with PyMW.
    58 
    59 === Running PyMW Applications ===
    60 
    61 '''''Note:''' the following assumes that you have a folder in your home directory called "pyboinc" containing the Python 2.6 binaries and that you have installed PyMW as described in the previous section.''
    62 
    63 First, you must setup a project for testing, I will call mine "sandbox" and it will be run on the local address I have given my VM, 192.168.1.190, but you should use whatever address or domain name that is setup on your VM:
    64 
    65 {{{
    66 $ cd ~/boinc/tools
    67 $ ./make_project --url_base http://192.168.1.190 sandbox
    68 
    69 (answer yes to all questions/warnings)
    70 }}}
    71 
    72 This may take a while to generate the server keys. After it's completed, you should go into your project directory and add it to your cron jobs and to the Apache server:
    73 
    74 {{{
    75 $ cd ~/projects/sandbox
    76 $ su -c 'cat sandbox.httpd.conf >> /etc/apache2/httpd.conf'
    77   (you'll be prompted for the root password, which is "rootpw")
    78 
    79 $ su -c 'apache2ctl -k restart'
    80 $ crontab sandbox.cronjob
    81 }}}
    82 
    83 The project should not be created, but there is no application installed (notice, we never called xadd or update_versions). Luckily, PyMW will do this for us. Now all we have to do is run our application with the boinc interface and point it to our home directory:
    84 
    85 {{{
    86 $ cd ~/pymw-0.2/examples
    87 $ python monte_pi.py -n 1 -i boinc -p /home/boincadm/projects/sandbox -c /home/boincadm/pyboinc -a 1.00_python26.zip
    88 
    89 (lots of information will scroll out and then it will eventually wait)
    90 }}}
    91 
    92 The Monte Carlo PI estimation application is waiting for BOINC clients to process it's work units. So go back to your main PC (not the VM) and open up the BOINC client (install it if needed).
    93 
    94 Once you have the BOINC manager open, click on "advanced view", when debugging it's best if you stay in this view. Next, click "Tools->Attach to project" from the main application menu. Click "Next" and then enter your project URL ("http://192.168.1.190/sandbox" if you are following this exactly) and then click next again.
    95 
    96 Now that you are attached to the project, it should be listed in the project view. Click on the project and click the "update" button to force it to request work from the server. The PyBOINC interpreter will download and then a handful of tasks should appear. Once these tasks complete you can hit "update" on the project again to force the client to send them back to the server.
    97 
    98 Back at the BOINC VM, you should now see the results of the computation.
    99 
    100 === Talking to BOINC from Python ===
    101 
    102 The PyBOINC interpreter also includes a custom module for interfacing with the BOINC client API under the namespace "boinc". Most common BOINC API functions have been implemented, to see a full list, run the following on the BOINC VM:
    103 
    104 {{{
    105 $ cd ~/pyboinc/linux
    106 
    107 (you may or may not need the next line)
    108 
    109 $ chmod +x pymw_1.03_i686-pc-linux-gnu
    110 $ echo -e "import boinc\n""print dir(boinc)" > boinc_test.py
    111 $ ./pymw_1.03_i686-pc-linux-gnu boinc_test.py 1.00_python26.zip
    112 }}}
    113 
    114 Accessing the boinc API in your code is as easy as importing the boinc namespace and then using the function you need, for example:
    115 
    116 {{{
    117 import boinc
    118 print boinc.time_to_checkpoint()
    119 }}}
    120 
    121 There are two things worth noting here, first, all boinc functions have the "boinc_" part of the C name removed, which is redundant when using the "boinc" namespace as a prefix. Secondly, the function boinc.get_app_name() is not actually part of the BOINC API, but is provided by PyBOINC to let you discover the true application name that was launched and not just your script name.
    122 
    123 See the PyMW /examples folder for more examples on using PyMW or go to the [http://pymw.sourceforge.net/ PyMW] web site for official documentation.
    1246
    1257== Using Py2Exe ==