GUI with blocking database access

Anton Vredegoor anton at vredegoor.doge.nl
Tue Nov 5 08:44:33 EST 2002


On 5 Nov 2002 03:22:06 -0800, scheff at bigfoot.de (Tim Scheffler) wrote:

>Dear all,
>
>I would like to construct a GUI to access an external database.
>Unfortunately I have to use a (non-opensource) python dll (WIN32)
>module provided by the database to write/read from/to it. If I/O is
>done via this module all execution is stopped if I try to run it in a
>separate thread in the GUI.

Can you get any I\O at all? I have had some success using Cygwin and
popen2 for buffered I\O and some trouble with using Windows 98 Python
for the same script. My situation is a bit different from yours I
think because I am on Windows 98 and I\O is broken for that platform
to begin with. The problem in my case is that I want to use pipes
between two console apps and have a python script in the middle to
communicate with the two apps. Luckily I have the sourcecode for the
console apps so I could in principle insert some flush calls in the
code and unblock I\O this way. Unluckily the console apps are large
and obscure so I had to write a smaller app for testing purposes.

>
>Does somebody have an idea how to construct a GUI, that can trigger
>such an I/O module? I thought about to run two separate processes on
>WIN-NT one that provides the GUI and one that runs the I/O and let
>them communicate through a pipe or something like that. But here I
>dont know how to start two processes from one python script as fork()
>wont work on WIN-NT.

Popen2 can have multiple pipes open at same time even on Windows 98.
It's just a problem to have the apps flush stdout. On cygwin this
problem does not exist I think.

If you can compile, this can be used as a test program:
(project3.cpp for Borland C++ Builder 4, adjust for your compiler)

#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(void)
{
        char input[100];
        char finish[10];
        int i = 1;

        strcpy(finish,"quit\0");

        while(i!=0){
        scanf("%s",&input);
        printf("%s\n",input);
        i = strcmp(input,finish);
        flushall();
        }
        return 0;
}


For gcc the corresponding flush() call would be fflush(stdout).

Use this python script to test popen2 I\O on windows or cygwin:
(for cygwin insert "./" or something like that in the executables
path)

import os
from string import strip

def process(s, inf, outf):
       outf.write("%s\n" %s)
       line = inf.readline()
       return strip(line)

def test():
    outf,inf = os.popen2("project3.exe")
    outf1,inf1 = os.popen2("project3.exe")
    line = process("hello",inf,outf)
    line1 = process(line,inf1,outf1)
    print line1
    process("quit",inf,outf)
    process("quit",inf1,outf1)

if __name__=='__main__':
    test()

>Any help is deeply appreciated.

I hope this helps. I am not sure I read your question correctly
however since I am a bit drained by jobhunting activities. Isn't
calldll used to communicate with dll's rather than creating processes
via popen2? You seem to be able to open one process though so I went
for it.

Good luck!

Anton.



More information about the Python-list mailing list