Tkinter/threading problem

Roeland Rengelink rrengeli at eso.org
Thu Sep 2 08:04:01 EDT 1999


Hi,

The following problem has me completely stumped, and I'm wondering
if somebody has a suggestion for were I should start looking for
the cause of the problem (Yep, it's that bad).

We are using python to script the processing of astronomical data
We have four threads:
- Main is a tkinter GUI
- Thread A does the actual processing
- Thread B retrieves data from tape
- Thread C stores data to tape.

Basically Thread A posts retrieval and storage requests to thread B
and C respectively. All threads rely heavily on os.system and os.popen
calls to do the actual work. The idea is that while A is processing, B
is retrieving the next piece of data and C stores the previous piece
of data. The GUI starts thread A with some relevant input
parameters. and after that does nothing.

The problem is the following.

After thread A posts a store-request to thread C, at some point thread
C executes:

 some_command = 'A command to get some info from the jukebox....'
 os.system(some_command)      # For testing only....
 pipe = os.popen(some_command,'r')
 result = pipe.readline()
 print result
 status = pipe.close()
 print status

When tested in a seperate environment this runs as expected. i.e.:
os.system(some_commands) dumps some lines to the screen, the first of
which is caught as expected by reading from the pipe when the
command is executed again by os.popen()

If, however I run this after a request from A, os.system(some_command)
behaves as expected, but os.popen(some_command), followed by
pipe.readline() only results in empty lines (pipe.close() always seems
to return without error).

If I use time.sleep() in thread A to suspend processing during the
execution of the storage requests, os.system(some_command) and
os.popen(some_command) give the correct results again.

If I don't use the GUI, but start thread A from Main directly, the
above fragment also works correctly

Apparently I'm doing something in thread A/GUI that interferes with the
pipe created in thread C. Needless to say, there is nothing in
thread A that comes even close to interfering with the jukebox that
is the subject of some_command in thread C. The culprit seems to be
the os.popen() function itself, in combination with mixing threading
and tkinter. Is there anything in particular that I should watch out
for? Basically, thread A is doing a bunch of os.system() and
os.popen() calls to shuffle data around and then call
a big iraf task (image-processing program).

I haven't been able to reproduce the problem in a small piece of code.
As I said I don't even know where to start.

Some system info:
Solaris5.6, 4CPU Ultra Sparc

Hope somebody can gimme a hint

Roeland Rengelink






More information about the Python-list mailing list