Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: A new CB reader

by choroba (Cardinal)
on Jul 07, 2017 at 00:09 UTC ( [id://1194423]=note: print w/replies, xml ) Need Help??

in reply to A new CB reader

You can now find another program in the repository, pm-cb-g, which is a GUI client. It's read/write and the basics should work, but I might add some bells and whistles later. It uses Thread::Queue and Tk.

What I don't understand is why the POST to the send chatter returns The Monastery Gates instead of the announced text "Chatter accepted".

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: A new CB reader
by LanX (Saint) on Jul 07, 2017 at 00:18 UTC
    > What I don't understand is why the POST to the send chatter returns The Monastery Gates instead of the announced text "Chatter accepted".

    Prayer to the gods: Please promote the choroba to pmdev, so he can at least drink - ehm read - from the sources of the monastery. ;-)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

        Yes, I realized the answer in the meantime. The problem was I used URI parameters instead of making the message part of the post content.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      If he asks for it, sure.

      I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
        OK, so I do. Hopefully, I'll be more successful than with my requests to join janitors.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: A new CB reader
by Discipulus (Canon) on Jul 07, 2017 at 08:57 UTC
    Thanks choroba!

    I just forked it and proposed a modification ( just added some color / size options ).

    Have you considered the possibility to use MCE for threading part? Will be an opportunity to show another example of usage of such module.

    Unfortunately I'm not able to modify your program in this direction: possibly some other monks will accept the challenge..

    Anyway thanks!


    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      Hi Discipulus. Just few line changes ( 3 places ). Here's the diff output.

      $ diff pm-cb-g pm-cb-g-hobo 27,28c27,28 < use threads (stack_size => 2 ** $stack_size); < use Thread::Queue; --- > use MCE::Hobo; > use MCE::Shared; 41c41 < my ($readQ, $writeQ) = map 'Thread::Queue'->new, 1, 2; --- > my ($readQ, $writeQ) = map { MCE::Shared->queue() } 1, 2; 43c43 < my $communicate_t = threads->create(\&communicate); --- > my $communicate_t = MCE::Hobo->create(\&communicate);

      Update. The stack_size option isn't needed when using MCE::Hobo. Below is the diff -u output.

      $ diff -u pm-cb-g pm-cb-g-hobo --- pm-cb-g 2017-07-07 16:05:39.000000000 -0500 +++ pm-cb-g-hobo 2017-07-07 16:32:36.782646208 -0500 @@ -6,12 +6,11 @@ use Getopt::Long qw( :config no_ignore_case ); -my ($bg_color, $fg_color, $author_color, $font_name, $char_size, - $stack_size); +my ($bg_color, $fg_color, $author_color, $font_name, $char_size); BEGIN { ($bg_color, $fg_color, $author_color, $font_name, $char_size, - $stack_size) = qw( white black blue Helvetica 12 15 ); + ) = qw( white black blue Helvetica 12 ); die "Invalid arguments!\n" unless GetOptions( 'a|author_color=s' => \$author_color, @@ -19,13 +18,12 @@ 'c|char_size=i' => \$char_size, 'f|fg_color=s' => \$fg_color, 'F|font_name=s' => \$font_name, - 's|stack_size=i' => \$stack_size, ); } -use threads (stack_size => 2 ** $stack_size); -use Thread::Queue; +use MCE::Hobo; +use MCE::Shared; use constant { @@ -38,9 +36,9 @@ }; -my ($readQ, $writeQ) = map 'Thread::Queue'->new, 1, 2; +my ($readQ, $writeQ) = map { MCE::Shared->queue() } 1, 2; -my $communicate_t = threads->create(\&communicate); +my $communicate_t = MCE::Hobo->create(\&communicate); gui();

      Regards, Mario

        Update: Made a fork so not having to apply the diff by hand if wanting to try The only benefit to using MCE::Child and MCE::Channel is that there is one less process on Unix platforms (i.e. no shared-manager process). choroba, please know that it is okay to reject this. I made a fork simply to test pm-cb-g using MCE::Child and MCE::Channel for my own validation.


        I released MCE 1.841 (includes MCE::Channel and MCE::Child) and MCE::Shared 1.841. During development, ran pm-cb-g using MCE::Child and MCE::Channel on my laptop (macOS) including a Windows 7 VM. Here is the diff output (long form).

        diff -aur pm-cb-master/lib/PM/CB/ pm-cb-master2/lib/PM/CB/Co --- pm-cb-master/lib/PM/CB/ 2019-06-08 16:07:06.000000000 + -0400 +++ pm-cb-master2/lib/PM/CB/ 2019-07-10 22:40:18.00000000 +0 -0400 @@ -15,6 +15,9 @@ sub start_comm { my ($self) = @_; $self->{communicate_t} = $self->{worker_class}->create(sub { + if ($INC{''}) { + $SIG{QUIT} = sub { threads->exit }; + } my $communication = PM::CB::Communication->new({ to_gui => $self->{to_gui}, from_gui => $self->{to_comm}, @@ -42,9 +45,11 @@ $self->{to_comm}->enqueue(['url']); }; } - $self->{to_comm}->insert(0, ['quit']); - $self->{communicate_t}->join; - $self->{to_gui}->insert(0, ['quit']); + if ($^O ne 'MSWin32' || ! $INC{'MCE/'}) { + $self->{communicate_t}->kill('QUIT'); + $self->{communicate_t}->join; + } + $self->{to_gui}->enqueue(['quit']); } diff -aur pm-cb-master/lib/PM/CB/ pm-cb-master2/lib/PM/CB/ --- pm-cb-master/lib/PM/CB/ 2019-06-08 16:07:06.000000000 -04 +00 +++ pm-cb-master2/lib/PM/CB/ 2019-07-06 15:17:07.000000000 -0 +400 @@ -673,7 +673,7 @@ sub quit { my ($self) = @_; print STDERR "Quitting...\n"; - $self->{to_control}->insert(0, ['quit']); + $self->{to_control}->enqueue(['quit']); } diff -aur pm-cb-master/pm-cb-g pm-cb-master2/pm-cb-g --- pm-cb-master/pm-cb-g 2019-06-08 16:07:06.000000000 -0400 +++ pm-cb-master2/pm-cb-g 2019-07-06 15:11:58.000000000 -0400 @@ -55,15 +55,15 @@ } -use if $mce => 'MCE::Hobo'; -use if $mce => 'MCE::Shared'; +use if $mce => 'MCE::Child'; +use if $mce => 'MCE::Channel'; use if ! $mce => threads => (stack_size => 2 ** $stack_size); use if ! $mce => 'Thread::Queue'; my ($queue_class, $queue_constructor, $worker_class) = $mce - ? ('MCE::Shared', 'queue', 'MCE::Hobo') + ? ('MCE::Channel', 'new', 'MCE::Child') : ('Thread::Queue', 'new', 'threads'); my ($to_gui, $to_comm, $to_control)

        The ->insert method is lacking in MCE::Channel due to an edge case so not implemented. Signaling workers is another way and works well using threads on Windows, MCE::Hobo or MCE::Child on Unix. Threads requires one to define the signal handler whereas MCE::Hobo and MCE::Child already configure $SIG{QUIT} to terminate.

        Update: I needed to enclose two lines above inside an if statement due to signal handling delayed for child processes (emulated) on the Windows platform. Perhaps the Tk loop is preventlng signaling from happening, am not sure. Tested the update on macOS and WIndows with and without the -m command-line switch.

        + if ( $^O ne 'MSWin32' || ! $INC{'MCE/'} ) { + $self->{communicate_t}->kill('QUIT'); + $self->{communicate_t}->join; + }

        Q. Why does MCE::Channel lack the insert method?

        A. Unlike MCE::Shared->queue, there is no manager process involvement in MCE::Channel. Thus, a worker holding a read lock on an empty channel (awaiting next item) makes it impossible for another worker inserting. Enqueue involves write lock only, but insert requires both read and write locks.

        Regards, Mario

Re^2: A new CB reader
by Tux (Canon) on Jul 07, 2017 at 06:39 UTC
    $ perl pm-cb-g Segmentation fault (core dumped) This is perl 5, version 26, subversion 0 (v5.26.0) built for x86_64-li +nux-thread-multi-ld $ gdb ... (gdb) where No stack. (gdb) run pm-cb-g Starting program: /pro/bin/perl pm-cb-g Missing separate debuginfos, use: zypper install glibc-debuginfo-2.22- +4.9.1.x86_64 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/". [New Thread 0x7ffff7e69700 (LWP 23651)] Thread 2 "perl" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff7e69700 (LWP 23651)] 0x00007ffff6d3e22c in _int_malloc () from /lib64/ Missing separate debuginfos, use: zypper install fontconfig-debuginfo- +2.11.1-2.2.x86_64 libX11-6-debuginfo-1.6.3-7.1.x86_64 libXau6-debugin +fo-1.0.8-7.4.x86_64 libXft2-debuginfo-2.3.2-4.22.x86_64 libXrender1-d +ebuginfo-0.9.9-4.1.x86_64 libbz2-1-debuginfo-1.0.6-101.6.x86_64 libex +pat1-debuginfo-2.1.0-19.1.x86_64 libfreetype6-debuginfo-2.6.3-2.3.1.x +86_64 liblzma5-debuginfo-5.2.3-112.15.x86_64 libpng16-16-debuginfo-1. +6.8-9.3.1.x86_64 libxcb1-debuginfo-1.11.1-2.25.x86_64 libxml2-2-debug +info-2.9.4-5.6.1.x86_64 libz1-debuginfo-1.2.8-10.1.x86_64 $ perl -d:Trace pm-cb-g : : >> /pro/lib/perl5/5.26.0/ *{"$callpkg\::$_"} = \&{"$p +kg\::$_"} foreach @_; >> /pro/lib/perl5/5.26.0/ *{"$callpkg\::$_"} = \&{"$p +kg\::$_"} foreach @_; >> /pro/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld/IO/ +use SelectSaver; >> /pro/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld/IO/ +use SelectSaver; >> /pro/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld/IO/ +use SelectSaver; >> /pro/lib/perl5/5.26.0/x86_64-linux-thread-multi-ld/IO/ +use IO::Seekable; Segmentation fault (core dumped)

    I'll dig when time permits

    Enjoy, Have FUN! H.Merijn
      Try increasing the stack_size parameter to threads.
      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Bingo! 2 ** 16 works fine

        BTW, the UI is a lot more usable when you'd change all ->pack; to ->pack (-expand => 1, -fill => "both");

        Some suggestions:

        • (auto) color user names
        • time stamps
        • align start of text (fixed width for user names)
        • search box
        • log all conversation
        • auto-color code sections
        • an option to use mono font for code sections and variable width font for "normal" conversations (*I* would NOT use that, but I know people who'd love that

        Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1194423]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-16 10:41 GMT
Find Nodes?
    Voting Booth?

    No recent polls found