Thread not working correctly under FreeBSD

Frederic Jolliton comp.lang.python at fred.jolliton.com
Thu Oct 23 12:09:27 EDT 2003


Hi,

Here is a small Python program that show curious behavior under
FreeBSD when using threads:

-=-=-=-
$ cat test.py
import os, sys, time, thread
if len( sys.argv ) < 2 :
        thread.start_new_thread(lambda : os.system("python test.py x"), ())
        time.sleep( 5 )
else :
        os.system('echo "Hello, World!"')
        print '~system'
-=-=-=-

This program run more or less the following:

python test.py
`- shell -c 'python test.py x'
   `- python test.py x
      `- shell -c 'echo "Hello World!"'

When run without argument from Linux (Gentoo, kernel 2.4.21, Python
2.2.3), the output is:

-=-=-=-
Hello, World!
~system
<5 seconds pause>
-=-=-=-

But, from FreeBSD, the ouput is:

-=-=-=-
Hello, World!
<5 seconds pause>
-=-=-=-

and, as shown, os.system('echo ...') never return ! (However, the
shell running 'echo' is correctly terminated.)

Tested with the following FreeBSD version:

 - 5.0-RELEASE (gcc 3.2.1) Python 2.2.2 and Python 2.3.2
 - 4.8-STABLE (gcc 2.95)

Bug, feature or misuse of the thread module ?

Regards,

-- 
Frédéric Jolliton




More information about the Python-list mailing list