Re: [Perl/Tk] background programs and Xlib errors w/ Proc::Simple

Slaven Rezic <[email protected]> 12 Feb 2007 22:27:37 +0100
Newsgroups gmane.comp.lang.perl.tk
Message-ID <[email protected]>
Brian Jackson <[email protected]> writes:

> Hi-
> 
> I'm in the process of porting my Perl/Tk app from Suse 8.2 and Tk 
> 800.024 to Suse 10.2 and Tk 804.027.
> 
> I'm currently using Proc::Simple to fire off background commands, 
> scripts, and sub routines from my application.
> 
> All works fine with Tk 800.024, but it barfs with Xlib errors on Tk 
> 804.027 then the Proc::Simple code/routine finishes running :(
> 
> ------------------------
> Xlib: unexpected async reply (sequence 0x1917)!
> X Error of failed request:  BadDrawable (invalid Pixmap or Window 
> parameter)
>   Major opcode of failed request:  53 (X_CreatePixmap)
>   Resource id in failed request:  0x7c0001f
>   Serial number of failed request:  6425
>   Current serial number in output stream:  6401
> 
> or 
> 
> X Error of failed request:  RenderBadPicture (invalid Picture parameter)
>   Major opcode of failed request:  156 (RENDER)
>   Minor opcode of failed request:  7 (RenderFreePicture)
>   Picture id in failed request: 0x8600234
>   Serial number of failed request:  19569
>   Current serial number in output stream:  19547
> -------------------------
> 
> Now, I've given Proc::Background a whirl, but it doesn't quite seem to 
> handle sub routines, only external scripts/commands, but I want to run 
> a subroutine as a background process.  And I do not care about exit 
> codes or when it finishes.  I'm packing up parameters and just wanting 
> to have it abuse the CPU in the background :)
> 
> I could convert 1 or 2 of the sub routines into standalone apps/scripts 
> and call them with Proc::Background, but one of them I send in a rich 
> hash and I wouldn't know how to handle the rich hash coming in.
> 
> In my Perl/Tk app, a sub-routine is launched when a button is pressed, 
> but during the run of the sub-routine, it does some work, then when it 
> hits a certain point, it needs to fire off some processing in the 
> background, and then return focus, and redraw the main screen so the 
> user can continue onto the next part of the application.
> 

In Perl/Tk it is usually not possible to have multiple processes
accessing the same X11 connection. I am not sure why it works for you
with Tk 800. A short script to reproduce this would be:

    use Tk;
    $top = new MainWindow;
    if (fork == 0) {
        $top->Button->pack;
        sleep 100;
    }
    MainLoop;

It's even not possible to change a variable in the child process:

    use Tk;
    $top = new MainWindow;
    $top->Label(-textvariable => \$foo)->pack;
    $top->update;
    if (fork == 0) {
        $foo = "hello";
        $top->update; # update is needed, otherwise the change wouldn't be seen by Tk
        sleep 100;
    }
    MainLoop;

Regards,
        Slaven

-- 
Slaven Rezic - slaven <at> rezic <dot> de

Tk-AppMaster: a perl/Tk module launcher designed for handhelds
	http://tk-appmaster.sf.net
--++**==--++**==--++**==--++**==--++**==--++**==--++**==
ptk mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/ptk