Created: 05-Dec-1997 Updated: 27-Jun-1997
Site Index of Changed Web Pages

Additions Made to the Official Python Release

This build includes support for most Python functionality as well as TCP/IP sockets. It omits the Posix ability to 'fork' a process but supports threads using OS/2 native capabilities. I have tried to support everything possible but here are a few usage notes.

PyREXX Extension Module

My PyREXX extension allows Python to invoke functions in REXX DLLs, giving Python access to many new interfaces, from SQL to serial I/O to multimedia.

os.popen() Usage Warnings

With respect to my implementation of popen() under OS/2:
    import os

    fd = os.popen("pkzip.exe -@ junk.zip", 'wb')
    fd.write("file1.txt\n")
    fd.write("file2.txt\n")
    fd.write("file3.txt\n")
    fd.write("\x1a")  # Should Not Be Necessary But Is
    fd.close()
There is a bug, either in the VAC++ compiler or OS/2 itself, where the simple closure of the write-side of a pipe -to- a process does not send an EOF to that process. I find I must explicitly write a control-Z (EOF) before closing the pipe. This is not a problem when using popen() in read mode. One other slight difference with my popen() is that I return None from the close(), instead of the Unix convention of the return code of the spawned program. I could find no easy way to do this under OS/2.

BEGINLIBPATH / ENDLIBPATH

With respect to environment variables, this OS/2 port supports the special-to-OS/2 magic names of 'BEGINLIBPATH' and 'ENDLIBPATH' to control where to load conventional DLLs from. Those names are intercepted and converted to calls on the OS/2 kernel APIs and are inherited by child processes, whether Python-based or not.

New Attributes in the 'os' Module

A few new attributes have been added to the os module:

Using Python as the Default OS/2 Batch Language

Note that OS/2 supports the Unix technique of putting the special comment line at the time of scripts e.g. "#!/usr/bin/python" in a different syntactic form. To do this, put your script into a file with a .CMD extension and added 'extproc' to the top as follows:
    extproc C:\Python\Python.exe -x
    import os
    print "Hello from Python"
The '-x' option tells Python to skip the first line of the file while processing the rest as normal Python source.

Recent Fixes/Compatability Improvements (Thanks to Michael Muller)

  1. Fix for chdir function.

    The existing chdir function didn't change the current drive under OS/2. Since the current working directory really consists of the current drive and the drive's current working directory, chdir should really change the drive as well (especially since there is no chdrive function).

  2. Fix for time.sleep()

    time.sleep() was using select() instead of DosSleep(), the native OS/2 sleep function that was written into the code for it. The select() method didn't work quite right, so DosSleep() is now being used.

  3. Fix to make OS/2 locks function according to spec.

    The python lock acquire() method blocks if the same thread attempts to acquire the lock a second time, and the release() method can release a lock that was acquired by another thread.

    The OS/2 implementation was based on OS/2 mutex semaphores, which are owned by a particular thread & process. As such, an attempt to re-acquire a lock from the owning thread always immediately succeeded and an attempt to release the lock from a non-owning thread always failed.

    Because of this, the standard Queue module didn't work under OS/2 - Queue uses locks as event semaphores which are triggered to notify another thread of an event.

    Locks under OS/2 were reimplemented using event semaphores and critical sections, and now they appear to function identically to the *NIX version.

    After implementing this fix, Fnorb's threaded model began to work under OS/2.


Pagemaster <jrush@summit-research.com>