zentara has asked for the wisdom of the Perl Monks concerning the following question:

Hi, the threaded Tk script at ztk-tvguide works fine on linux. When I try to run it on windows, I get an error, like:

Panic cond_init(0) and a bogging down

It would be nice if I could get this to run on Windows, (so the rest of the world can use it :-) ) . If any of you Win32 gurus could tell me why it does this, I would be grateful. I'm testing it on WindowsME and ActiveStatePerl. Thanks.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Running a threaded Tk script on Windows

Replies are listed 'Best First'.
Re: Running a threaded Tk script on Windows
by Errto (Vicar) on Sep 15, 2005 at 19:52 UTC

    One issue might be the fact that you've loaded Tk, which is an XS module, and then spawned threads, which attempts to duplicate the data (even though you only use the Tk objects from one of the threads). The way around this is to replace your use Tk and use Tk::Something statements with require statements and place these after the point in the code where you launch your threads.

    Update: to give proper credit, I got this idea from BrowserUk in a node I can't find but it might have been this one.

      Thanks for the ideas. But I do spawn the threads before I start any Tk code, and it does run fine on linux. But it's a good possibility that windows needs the "use Tk" after the threads are up and running.

      I'm also wondering if it has something to do with using $ENV{tz} on windows?


      I'm not really a human, but I play one on earth. flash japh
        Thanks for the ideas. But I do spawn the threads before I start any Tk code, and it does run fine on linux.
        Just because it works on linux doesn't mean its supposed to :) and the mere act of useing the module executes code. From perlthrtut
        If you're using a module that's not thread-safe for some reason, you can protect yourself by using it from one, and only one thread at all. If you need multiple threads to access such a module, you can use semaphores and lots of programming discipline to control access to it.
        Tk is not thread-safe.

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Running a threaded Tk script on Windows
by renodino (Curate) on Sep 16, 2005 at 16:50 UTC
    You failed mention which version of Perl you were using on Win32 ?

    FYI: This is one of the issues I'm trying to address w/ Thread::Apartment (see also Apartment Threading in Perl), if I ever manage to get the proxied closure business figured out...

    Also, does this tool have the ability to display just specific categories of programs (in my case, sports ?) I've been dealing with various online tvguides for that purpose over the years w/ limited success.

      I was using ActiveState 5.8.6.811 on WindowsME. I just downloaded ActiveState 5.8.7.813 and will try it out. I'll let you know if I have any successs.

      The whole reason I used threads was that win32 has all sorts of problems with fileevent and IPC::Open3, and I "thought" threads would make it easier to get to run on win32. I was wrong. :-)


      I'm not really a human, but I play one on earth. flash japh
        I've actually had better threads success w/ 5.8.6 on Win32 (XP to be precise); 5.8.7 occasionally throws some odd errors out of threads::shared. At least, thats been the case while testing DBIx::Threaded, Thread::Queue::Duplex, and Thread::Apartment.

        As an independent test of a similar environment, you might want to try installing DBIx::Threaded and testing with DBD::SQLite, as it has many of the same issues as Perl/Tk (ie, lots of XS code, not threadsafe, but can be run inside its own thread). If it coughs, it might be a problem with your configuration or WinME (I've never used the latter w/ Perl threads, only WinXP or 2K).

      Hi again, i did get my basic thread model to finally run on windows, the code is below. My tvguide code still fails, but I really don't think it's Tk. It must be something else, and I guess I will have to manually rebuild the entire code from scratch on windows, testing at each step, to see what causes it to fail. It looks like I can get it to work, with an afternoon of fiddling with it. :-)

      I'm not really a human, but I play one on earth. flash japh
Re: Running a threaded Tk script on Windows
by zentara (Cardinal) on Sep 16, 2005 at 21:38 UTC
    Well, I found what the "glitch" was. It wasn't Tk. I declared some shared variables in a deep hash for about 1800 entries.
    my %days; my @chs = qw (1..30); my $max_prog_chan = 60; foreach my $channel(@chs){ foreach my $count(0..$max_prog_chan){ share $days{$channel}{$count}{'channel'}; share $days{$channel}{$count}{'channel_info'}; share $days{$channel}{$count}{'episode_num'}; share $days{$channel}{$count}{'start'}; share $days{$channel}{$count}{'stop'}; share $days{$channel}{$count}{'makedate'}; share $days{$channel}{$count}{'description'}; share $days{$channel}{$count}{'title'}; share $days{$channel}{$count}{'writer'}; share $days{$channel}{$count}{'director'}; share $days{$channel}{$count}{'actors'}; share $days{$channel}{$count}{'rating'}; share $days{$channel}{$count}{'length'}; share $days{$channel}{$count}{'category'}; share $days{$channel}{$count}{'star_rating'}; } }
    That just bogged down things on WindowsMe, but linux just whizzed thru it. I changed it to the following and got things to go ( for the most part).
    my %days; my @chs = qw (1..30); my $max_prog_chan = 60; foreach my $channel(@chs){ foreach my $count(0..$max_prog_chan){ share $days{$channel}{$count}; } }
    So it seems Windows didn't like all those explicitly named shared assignments.

    I'm not really a human, but I play one on earth. flash japh