home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / py2s152.zip / README.OS2 < prev   
Text File  |  1999-06-27  |  7KB  |  195 lines

  1. Python/2 -- The Python Interpreter for OS/2
  2. ===========================================
  3.  
  4. Assuming you have downloaded the binaries from my web site at
  5. http://warped.cswnet.com/~jrush/python_os2, you are ready to
  6. enter the wonderful world of Python programming.  To learn
  7. more, just point your browser to the file x:\Python\html\index.html
  8. on your local disk and begin reading.
  9.  
  10. For my non-OS/2 Python-related work, check out my other web page at:
  11.  
  12.     http://starship.python.net/crew/jrush.
  13.  
  14.  
  15. -- Suggested Environment Variable Setup
  16.  
  17. With respect to the environment variables for Python, I use the
  18. following setup:
  19.  
  20.     Set PYTHONHOME=C:\Python
  21.     Set PYTHONPATH=.;C:\Python\Lib; \
  22.                      C:\Python\Lib\plat-win; \
  23.                      C:\Python\Lib\lib-tk; \
  24.              C:\Python\Lib\lib-dynload; \
  25.              C:\Python\Lib\site-packages; \
  26.              C:\Python\Lib\dos-8x3
  27.  
  28. Place any Python extension DLLs (often named .pyd instead of .dll)
  29. you acquire into:
  30.  
  31.     C:\Python\Lib\lib-dynload
  32.  
  33. and add-on software in Python source form into:
  34.  
  35.     C:\Python\Lib\site-packages\<pkgname>
  36.  
  37.  
  38. -- Testing your Installation
  39.  
  40. To Test your Installation, you can run the standard Python regression
  41. test suite, by running the following commands:
  42.  
  43.     python C:\Python\lib\test\regrtest.py
  44.  
  45.  
  46. -- Using Python as the Default OS/2 Batch Language
  47.  
  48. Note that OS/2 supports the Unix technique of putting the special
  49. comment line at the time of scripts e.g. "#!/usr/bin/python" in
  50. a different syntactic form.  To do this, put your script into a file
  51. with a .CMD extension and added 'extproc' to the top as follows:
  52.  
  53.     extproc C:\Python\Python.exe -x
  54.     import os
  55.     print "Hello from Python"
  56.  
  57. The '-x' option tells Python to skip the first line of the file
  58. while processing the rest as normal Python source.
  59.  
  60. If you are using the popular 4OS2 command shell replacement, you
  61. can jus set an environment variable as:
  62.  
  63.     Set .PY=D:\Python\Python.exe
  64.  
  65. and any file with an extension of .py will automatically be executable.
  66. This is a nice feature of 4OS2.
  67.  
  68.  
  69. -- Functionality
  70.  
  71. This build includes support for most Python functionality as well as
  72. TCP/IP sockets.  It omits the Posix ability to 'fork' a process but
  73. supports threads using OS/2 native capabilities.  I have tried to
  74. support everything possible but here are a few usage notes.
  75.  
  76.  
  77. -- os.popen() Usage Warnings
  78.  
  79. With respect to my implementation of popen() under OS/2:
  80.  
  81.     import os
  82.  
  83.     fd = os.popen("pkzip.exe -@ junk.zip", 'wb')
  84.     fd.write("file1.txt\n")
  85.     fd.write("file2.txt\n")
  86.     fd.write("file3.txt\n")
  87.     fd.write("\x1a")  # Should Not Be Necessary But Is
  88.     fd.close()
  89.  
  90. There is a bug, either in the VAC++ compiler or OS/2 itself, where the
  91. simple closure of the write-side of a pipe -to- a process does not
  92. send an EOF to that process.  I find I must explicitly write a
  93. control-Z (EOF) before closing the pipe.  This is not a problem when
  94. using popen() in read mode.
  95.  
  96. One other slight difference with my popen() is that I return None
  97. from the close(), instead of the Unix convention of the return code
  98. of the spawned program.  I could find no easy way to do this under
  99. OS/2.
  100.  
  101.  
  102. -- BEGINLIBPATH/ENDLIBPATH
  103.  
  104. With respect to environment variables, this OS/2 port supports the
  105. special-to-OS/2 magic names of 'BEGINLIBPATH' and 'ENDLIBPATH' to
  106. control where to load conventional DLLs from.  Those names are
  107. intercepted and converted to calls on the OS/2 kernel APIs and
  108. are inherited by child processes, whether Python-based or not.
  109.  
  110. A few new attributes have been added to the os module:
  111.  
  112.     os.meminstalled  # Count of Bytes of RAM Installed on Machine
  113.     os.memkernel     # Count of Bytes of RAM Reserved (Non-Swappable)
  114.     os.memvirtual    # Count of Bytes of Virtual RAM Possible
  115.     os.timeslice     # Duration of Scheduler Timeslice, in Milliseconds
  116.     os.maxpathlen    # Maximum Length of a Path Specification, in chars
  117.     os.maxnamelen    # Maximum Length of a Single Dir/File Name, in chars
  118.     os.version       # Version of OS/2 Being Run e.g. "4.00"
  119.     os.revision      # Revision of OS/2 Being Run (usually zero)
  120.     os.bootdrive     # Drive that System Booted From e.g. "C:"
  121.                      # (useful to find the CONFIG.SYS used to boot with)
  122.  
  123.  
  124. -- Recent Fixes/Compatability Improvements (Thanks to Michael Muller)
  125.  
  126. 1) Fix for chdir function.
  127.  
  128.    The existing chdir function didn't change the current drive under OS/2.
  129.    Since the current working directory really consists of the current drive
  130.    and the drive's current working directory, chdir should really change the
  131.    drive as well (especially since there is no chdrive function).
  132.  
  133. 2) Fix for time.sleep()
  134.  
  135.    time.sleep() was using select() instead of DosSleep(), the native OS/2
  136.    sleep function that was written into the code for it.  The select()
  137.    method didn't work quite right, so DosSleep() is now being used.
  138.  
  139. 3) Fix to make OS/2 locks function according to spec.
  140.  
  141.    The python lock acquire() method blocks if the same thread attempts
  142.    to acquire the lock a second time, and the release() method can release
  143.    a lock that was acquired by another thread.
  144.  
  145.    The OS/2 implementation was based on OS/2 mutex semaphores, which are
  146.    owned by a particular thread & process.  As such, an attempt to
  147.    re-acquire a lock from the owning thread always immediately succeeded and
  148.    an attempt to release the lock from a non-owning thread always failed.
  149.  
  150.    Because of this, the standard Queue module didn't work under OS/2 - Queue
  151.    uses locks as event semaphores which are triggered to notify another
  152.    thread of an event.
  153.  
  154.    Locks under OS/2 were reimplemented using event semaphores and critical
  155.    sections, and now they appear to function identically to the *NIX version.
  156.    
  157.    After implementing this fix, Fnorb's threaded model began to work under
  158.    OS/2.
  159.  
  160.  
  161. Rebuilding Using IBM VisualAge C/C++ for OS/2
  162. =============================================
  163.  
  164. If you have installed the source package, to build Python for OS/2,
  165. change into PC/os2vacpp and issue an 'NMAKE' command.  This will
  166. build a PYTHON15.DLL containing the set of Python modules listed
  167. in config.c and a small PYTHON.EXE to start the interpreter.
  168.  
  169. By changing the C compiler flag /Gd- in the makefile to /Gd+, you can
  170. reduce the size of these by causing Python to dynamically link to the
  171. C runtime DLLs instead of including their bulk in your binaries. 
  172. However, this means that any system on which you run Python must have
  173. the VAC++ compiler installed in order to have those DLLs available.
  174.  
  175. During the build process you may see a couple of harmless warnings:
  176.  
  177.   From the C Compiler, "No function prototype given for XXX", which
  178.   comes from the use of K&R parameters within Python for portability.
  179.  
  180.   From the ILIB librarian, "Module Not Found (XXX)", which comes
  181.   from its attempt to perform the (-+) operation, which removes and
  182.   then adds a .OBJ to the library.  The first time a build is done,
  183.   it obviously cannot remove what is not yet built.
  184.  
  185. Note that the makefile that ships with this release requires the
  186. Warp 4 Toolkit headers and the MPTN Developer Kit headers/libraries.
  187.  
  188. -- Contact Info
  189.  
  190. If you have questions, suggestions or problems specifically with
  191. the OS/2 VAC++ port of Python, please contact me at:
  192.  
  193.     Jeff Rush <jrush@summit-research.com>
  194.  
  195.