IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Interfaces Graphiques Perl Discussion :

Threads et Perl/Tk


Sujet :

Interfaces Graphiques Perl

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut Threads et Perl/Tk
    Salut Merci pour l'article. J'ai essayé d'utiliser votre script dans mon application GUI.
    Actuellement, je suis confronté à un problème. Je ne suis pas en mesure d'appeller la fonction qui est dans le thread.
    exemple:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    sub run_script_tk {
     
         if ($paste_text) {
     
     
        $FunctionName = "run_script";  # He says the procedure to call
     
        @ArgumentsThread = ($paste_text);  # He is given the arguments
     
        $ThreadWork   = 1;             # Asked to work
     
     
     
        #  ===> Modification (Rajout) <=============
     
        # Button is deactivated List Files
     
        #$run_button->configure(-state => "disabled");
     
     
     
        # As long as the thread work, we expect
     
        while ( $ThreadWork == 1 ) {
     
          sleep 0.2;
     
          $f ->update;
     
        }
     
     
     
     
     
        # It reactivates the List Files button
     
        $run_button->configure(-state => "normal");
     
     
     
       }  
     
      return;
     
    }
    Il mentionne une erreur disant
    valeur invalide à la variable partagée
    à

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $FunctionName = "run_script";
    Je ne suis pas en mesure d'attribuer un nom de fonction à la variable partagée


    votre aide est très appréciée. Je travaille sur Ubuntu pour mon interface graphique.

  2. #2
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Dans l'article, il est bien mentionné de déclarer les variables nécessaires et à partager en début de programmes. J'ai l'impression que vous n'avez pas bien lu ou compris l'article (surement à cause de la langue). Il faudrait nous montrer votre code plus complet.

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut Threads & TK
    J'ai bien compris votre article! J'ai partagé toutes les variables.
    Voici mon problème, j'ai créer une image de boutons dans le cadre.
    Je veux faire de ce boutons d'image multithread. Lorsque j'ai
    assigner les arguments et le nom de fonction pour varibles partagé
    Je reçois le problème. J'ai inclus un morceau de code de ma
    application. S'il vous plaît analyser et si vous avez des doutes faites le moi savoir.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    use threads;                    
    use threads::shared;         
    use Time::HiRes qw( sleep );
     
    my %FunctionsToLaunchThread  = ( "run_script" => \&run_script, );
     
     
    # Threads and shared variables
    my $KillThread : shared;       
    my $FunctionName : shared; l
    my $ThreadWork : shared;    
    my @ArgumentsThread : shared;   
    my $RefResultFunction : shared; 
     
    $ThreadWork = 0;               
    $KillThread     = 0;              
     
    # Creation of thread
    my $Thread = threads->create( \&WorkThread );
     
     
    use Tk; 
     
     
     
     
    #create a frame at top
     
     
    my $f = $mw->Frame(-borderwidth => 2, -relief => 'groove')
    	->pack(-side => 'top', -fill => 'both');
    my $tab = $mw->NoteBook()->pack( -fill=>'both', -expand=>1 );
     
    #create image icons at frame
     
    #creating buttons with image
    $f->Button(-image => $save,
             -text => 'Save',-state => 'disabled',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
    my $run_button=$f->Button(-image => $play,
             -text => 'Play',-state => 'disabled',
               )->pack(-side => 'left', -anchor => 'n'); 
    $f->Button(-image => $record,
             -text => 'Record',-state => 'disabled',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
    my $stop_button=$f->Button(-image => $stop,
             -text => 'Stop',-state => 'disabled',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
    $f->Button(-image => $medi,
             -text => 'Medi',-state => 'disabled',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
    $f->Button(-image => $phone,
             -text => 'Phone',-state => 'disabled',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
    $f->Button(-image => $help,
             -text => 'Help',-state => 'normal',
            -command => sub{do_search()}
        )->pack(-side => 'left', -anchor => 'n'); 
     
     
    sub load_cells 
    { 
    $tab->delete("Sheet 5");
    $sheet4 = $tab->add("Sheet 5", -label=>"Test Run");
     
    my $run_text;
    my $label = $sheet4->Label(-width=>15);
     
     
    my $main_frame = $sheet4->Frame(-border => 2,-relief => 'ridge')->pack(-side => 'top', -fill => 'y');
    my $top_frame = $main_frame->Frame(-background => "red")->pack(-side =>'top', -fill => 'x');
    my $left_frame = $main_frame->Frame(-background => "black",)->pack( -side => 'left',-fill => 'both');  
     
    my $right_frame = $main_frame->Frame(-background => "white",-relief => 'groove')->pack(-side => "right",-fill => 'both');
    $top_frame->Label(-text => "All-In-One Test!",-background => "red")->pack(-side => "top");
     
    $sub_description_text=$right_frame->Scrolled('ROText',
    			     -height => '20',
    			     -width => '60',
    			     -scrollbars => 'e',
    			    -background => "grey",
    			    -foreground => "black",
    			    -state=>'normal',
     
    			     )->pack(-fill => 'x',-side => "left",-anchor=>'n' );
    $paste_text = $right_frame->Text(-background => "grey",-foreground => "black"  )->pack(-fill => 'both',-side => "right");
    #$code_text = $right_frame->Text(-background => "white",-foreground => "black" )->pack(-fill => 'both',-side => "right");
     
    $paste_text->configure(-height      => 15,   # 5 lines high
    		 -background  => 'white',
    		 -foreground  => 'black',
    		 -width       => 40,
    		 -wrap        => 'word',
     		 -font        => 
    		 '-adobe-helvetica-bold-r-normal--0-120-75-75-p-63-iso8859-1');
    #my $clear_text = $right_frame->Button(-text => "Clear Text",
                   #                          -command =>[ \&clear_entry ,$paste_text])->pack(-side => "right");
     
     
     
    #$right_frame->Button(-text => "Run",-command =>[ \&run_script ,$paste_text])->pack(-side => "left");
     
    #my $thr = threads->new(\&fill_sim_memory,
     
    $run_button->configure(-command =>[ (\&runtk, $paste_text )],-state => 'normal');
    $stop_button->configure(-command =>[ \&stop],-state => 'normal');
    $tab->raise("Sheet 5");
     
    my $tree = $left_frame->Scrolled( 'Tree',
    -separator => '/',
    -background => 'white',
    -foreground => 'blue',
    -relief => 'groove',
    -exportselection => 1,
    -scrollbars => 'ne',
    -height => 40,
    -width => 60,
    -itemtype => 'text',
    -selectmode => "single",
    -browsecmd => sub{
    my $DN = shift;
    #print " Hello $DN";
    #$label->configure(-text=>$DN);
    &load_function($DN);
    }
     
    );
     
    sub runtk {
     
          $FunctionName = "run_script";  # He says the procedure to call
        @ArgumentsThread = ( $_[0]);  # He is given the arguments
        $ThreadWork   = 1;             # Asked to work
     
        #  ===> Modification (Rajout) <=============
        # Button is deactivated List Files
        $run_button->configure(-state => "disabled");
     
        # As long as the thread work, we expect
        while ( $$ThreadWork == 1 ) {
          sleep 0.2;
          $f ->update;
        }
     
       # $Message = "Listings des fichiers fini";
        # It reactivates the List Files button
        $run_button->configure(-state => "normal");
     
        # It displays the resulat
       # my $NbrFichier = scalar( @{$RefResultatFonction} );
        #print "Nombre de fichiers : $NbrFichier\n"; 
       # foreach my $Fichier ( @{$RefResultatFonction} ) {
          #print "- $Fichier\n";
        }
     
      }
      return;
    }
     
     
     
     
     
     
     
     
    sub run_script{
     
    my $text_data = $_[0];
     
     
    my $new=$text_data->get('1.0','end');
    open (MYFILE, "+>subroutines.txt") or die "cant open $!";
    print MYFILE $new;
    close MYFILE;
     
    open (MYFILE1, "subroutines.txt");
    my @sub_lines = <MYFILE1>;
    close MYFILE1;
     
     
    #----------------
     
     
    my $current =  localtime(time);
    #print "Current date and time is $current";
     
    use POSIX qw(strftime);
    my $now_string = strftime "%d-%b-%Y--%T", localtime;
    print $now_string;
     
     
    my $str ="$now_string.txt";
    print $str;
    open FILE, "+>>Test_Results/$str" or die $!;
     
     
     
    do "addcontact.pl";
     
    $f->update;
     
    do "call_contact.pl";
     
     
    use Device::Modem::GSM;
     
     my $modem = new Device::Modem::GSM( port => "/dev/$port_global",log => "file,$now_string.log",
                                                              loglevel => 'debug',  # default is 'warning'
     
     
                                                           );
     
     
     
     
    use Test::More  "no_plan";
    for(my $w=0;$w<@sub_lines ;$w++){
    	print $sub_lines[$w] ;
     	my $test1="PB001";
    	my $status;
    	if($sub_lines[$w] =~ m/$test1/ ){
    	print "yes";
     
    	$status =adcon($port_global);
    	print " The result is $status\n";
           		 if ($status eq "pass"){
    		 print "pass";        
    	   	 print FILE "$test1=Pass\n";
             	}
    		else {
    		print "fail";        
    		print FILE "$test1=fail\n";
            	 }
    	}
    	my $test2="PB002";
    	if($sub_lines[$w] =~ m/$test2/ ){
    	print "yes";
    	do "delete_contact.pl";
    	$status = delcon($port_global);
    	print " The result is $status\n";
    	 if ($status eq "pass"){
    		 print "pass";        
    	   	 print FILE "$test2=Pass\n";
             	}
    		else {
    		print "fail";        
    		print FILE "$test2=fail\n";
            	}
    	}
     
    	my $test3="PB003";
    	if($sub_lines[$w] =~ m/$test3/ ){
    	print "yes";
    	do "search_name.pl";
    	$status = searchname($port_global);
    	print " The result is $status\n";
    	 if ($status == 0){
    		 print "pass";        
    	   	 print FILE "$test3=Pass\n";
             	}
    		else {
    		print "fail";        
    		print FILE "$test3=fail\n";
            	 }
     
    	}
     
     
    	my $test4="PB004";
    	if($sub_lines[$w] =~ m/$test4/ ){
    	print "yes";
     	do "call_contact.pl";
    	$status =callcon($port_global); 
    	print " The result is $status\n";
    	 if ($status eq "pass"){
    		 print "pass";        
    	   	 print FILE "$test4=Pass\n";
             	}
    		else {
    		print "fail";        
    		print FILE "$test4=fail\n";
            	 }
     
    	}
     
     
    	my $test5="PB005";
    	if($sub_lines[$w] =~ m/$test5/ ){
    	print "yes";
    	do "messsage_contact.pl";
    	$status = messcon($port_global); 
    	print "The result is $status\n";
    	 if ($status  eq "pass"){
    		 print "pass";        
    	   	 print FILE "$test5=Pass\n";
             	}
    		else {
    		print "fail";        
    		print FILE "$test5=fail\n";
            	 }
     
    	}
     
     
     
     
     
     
     
    }
     
     
     
    close FILE;
     
     
     
    }
     
     
     
     
     
    #================================================
    # Our Unique Thread
    #================================================
    sub WorkThread {
     
      # Around in circles
      while (1) {
     
        # asked the thread to work
        if ( $ThreadWork == 1 ) {
     
          # Launches the process and get the result
          my @Result = $FunctionsToLaunchThread{$FunctionName}->(@ArgumentsThread);
          $RefResultFunction = shared_clone( \@Result);
     
          # asked the thread to sleep
          $ThreadWork = 0;
        }
     
        #Complete thread
        last if ( $KillThread == 1 );
     
        sleep 0.5;
      }
      return;
    }

  4. #4
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Premièrement, dans tout script Perl, je vous recommande de toujours utiliser les modules suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    use strict;
    use warnings;
    Cela vous éviterez d'avoir des erreurs de syntaxes comme
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    my $FunctionName : shared; l
    ou des soucis de placements de codes
    Global symbol "$mw" requires explicit package name at test.pl line 28.
    Global symbol "$mw" requires explicit package name at test.pl line 29.
    Global symbol "$save" requires explicit package name at test.pl line 35.
    Global symbol "$play" requires explicit package name at test.pl line 41.
    Global symbol "$record" requires explicit package name at test.pl line 46.
    Global symbol "$stop" requires explicit package name at test.pl line 52.
    Global symbol "$medi" requires explicit package name at test.pl line 58.
    Global symbol "$phone" requires explicit package name at test.pl line 64.
    Global symbol "$help" requires explicit package name at test.pl line 70.
    Global symbol "$sheet4" requires explicit package name at test.pl line 78.
    Global symbol "$sheet4" requires explicit package name at test.pl line 81.
    Global symbol "$sheet4" requires explicit package name at test.pl line 83.
    Global symbol "$sub_description_text" requires explicit package name at test.pl line 91.
    Global symbol "$paste_text" requires explicit package name at test.pl line 101.
    Global symbol "$paste_text" requires explicit package name at test.pl line 106.
    Global symbol "$paste_text" requires explicit package name at test.pl line 122.
    Unmatched right curly bracket at test.pl line 177, at end of line
    test.pl has too many errors.
    Donc corrige ce code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    #!/usr/bin/perl
    use strict;
    use warnings;
     
    use threads;
    use threads::shared;
    use Time::HiRes qw( sleep );
     
    my %FunctionsToLaunchThread = ( "run_script" => \&run_script, );
     
    # Threads and shared variables
    my $KillThread : shared;
    my $FunctionName : shared;
    my $ThreadWork : shared;
    my @ArgumentsThread : shared;
    my $RefResultFunction : shared;
     
    $ThreadWork = 0;
    $KillThread = 0;
     
    # Creation of thread
    my $Thread = threads->create( \&WorkThread );
     
    use Tk;
     
    #create a frame at top
     
    my $f = $mw->Frame( -borderwidth => 2, -relief => 'groove' )->pack( -side => 'top', -fill => 'both' );
    my $tab = $mw->NoteBook()->pack( -fill => 'both', -expand => 1 );
     
    #create image icons at frame
     
    #creating buttons with image
    $f->Button(
      -image   => $save,
      -text    => 'Save',
      -state   => 'disabled',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
    my $run_button = $f->Button(
      -image => $play,
      -text  => 'Play',
      -state => 'disabled',
    )->pack( -side => 'left', -anchor => 'n' );
    $f->Button(
      -image   => $record,
      -text    => 'Record',
      -state   => 'disabled',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
    my $stop_button = $f->Button(
      -image   => $stop,
      -text    => 'Stop',
      -state   => 'disabled',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
    $f->Button(
      -image   => $medi,
      -text    => 'Medi',
      -state   => 'disabled',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
    $f->Button(
      -image   => $phone,
      -text    => 'Phone',
      -state   => 'disabled',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
    $f->Button(
      -image   => $help,
      -text    => 'Help',
      -state   => 'normal',
      -command => sub { do_search() }
    )->pack( -side => 'left', -anchor => 'n' );
     
    sub load_cells {
      $tab->delete("Sheet 5");
      $sheet4 = $tab->add( "Sheet 5", -label => "Test Run" );
     
      my $run_text;
      my $label = $sheet4->Label( -width => 15 );
     
      my $main_frame = $sheet4->Frame( -border => 2, -relief => 'ridge' )->pack( -side => 'top', -fill => 'y' );
      my $top_frame = $main_frame->Frame( -background => "red" )->pack( -side => 'top', -fill => 'x' );
      my $left_frame = $main_frame->Frame( -background => "black", )->pack( -side => 'left', -fill => 'both' );
     
      my $right_frame = $main_frame->Frame( -background => "white", -relief => 'groove' )
        ->pack( -side => "right", -fill => 'both' );
      $top_frame->Label( -text => "All-In-One Test!", -background => "red" )->pack( -side => "top" );
     
      $sub_description_text = $right_frame->Scrolled(
        'ROText',
        -height     => '20',
        -width      => '60',
        -scrollbars => 'e',
        -background => "grey",
        -foreground => "black",
        -state      => 'normal',
     
      )->pack( -fill => 'x', -side => "left", -anchor => 'n' );
      $paste_text = $right_frame->Text( -background => "grey", -foreground => "black" )
        ->pack( -fill => 'both', -side => "right" );
     
    #$code_text = $right_frame->Text(-background => "white",-foreground => "black" )->pack(-fill => 'both',-side => "right");
     
      $paste_text->configure(
        -height     => 15,                                                            # 5 lines high
        -background => 'white',
        -foreground => 'black',
        -width      => 40,
        -wrap       => 'word',
        -font       => '-adobe-helvetica-bold-r-normal--0-120-75-75-p-63-iso8859-1'
      );
     
      #my $clear_text = $right_frame->Button(-text => "Clear Text",
      #                          -command =>[ \&clear_entry ,$paste_text])->pack(-side => "right");
     
      #$right_frame->Button(-text => "Run",-command =>[ \&run_script ,$paste_text])->pack(-side => "left");
     
      #my $thr = threads->new(\&fill_sim_memory,
     
      $run_button->configure( -command => [ ( \&runtk, $paste_text ) ], -state => 'normal' );
      $stop_button->configure( -command => [ \&stop ], -state => 'normal' );
      $tab->raise("Sheet 5");
     
      my $tree = $left_frame->Scrolled(
        'Tree',
        -separator       => '/',
        -background      => 'white',
        -foreground      => 'blue',
        -relief          => 'groove',
        -exportselection => 1,
        -scrollbars      => 'ne',
        -height          => 40,
        -width           => 60,
        -itemtype        => 'text',
        -selectmode      => "single",
        -browsecmd       => sub {
          my $DN = shift;
     
          #print " Hello $DN";
          #$label->configure(-text=>$DN);
          &load_function($DN);
          }
     
      );
     
      sub runtk {
     
        $FunctionName    = "run_script";    # He says the procedure to call
        @ArgumentsThread = ( $_[0] );       # He is given the arguments
        $ThreadWork      = 1;               # Asked to work
     
        #  ===> Modification (Rajout) <=============
        # Button is deactivated List Files
        $run_button->configure( -state => "disabled" );
     
        # As long as the thread work, we expect
        while ( $$ThreadWork == 1 ) {
          sleep 0.2;
          $f->update;
        }
     
        # $Message = "Listings des fichiers fini";
        # It reactivates the List Files button
        $run_button->configure( -state => "normal" );
     
        # It displays the resulat
        # my $NbrFichier = scalar( @{$RefResultatFonction} );
        #print "Nombre de fichiers : $NbrFichier\n";
        # foreach my $Fichier ( @{$RefResultatFonction} ) {
        #print "- $Fichier\n";
      }
     
    }
    return;
    }
     
    sub run_script {
     
      my $text_data = $_[0];
     
      my $new = $text_data->get( '1.0', 'end' );
      open( MYFILE, "+>subroutines.txt" ) or die "cant open $!";
      print MYFILE $new;
      close MYFILE;
     
      open( MYFILE1, "subroutines.txt" );
      my @sub_lines = <MYFILE1>;
      close MYFILE1;
     
      #----------------
     
      my $current = localtime(time);
     
      #print "Current date and time is $current";
     
      use POSIX qw(strftime);
      my $now_string = strftime "%d-%b-%Y--%T", localtime;
      print $now_string;
     
      my $str = "$now_string.txt";
      print $str;
      open FILE, "+>>Test_Results/$str" or die $!;
     
      do "addcontact.pl";
     
      $f->update;
     
      do "call_contact.pl";
     
      use Device::Modem::GSM;
     
      my $modem = new Device::Modem::GSM(
        port     => "/dev/$port_global",
        log      => "file,$now_string.log",
        loglevel => 'debug',                  # default is 'warning'
     
      );
     
      use Test::More "no_plan";
      for ( my $w = 0; $w < @sub_lines; $w++ ) {
        print $sub_lines[$w];
        my $test1 = "PB001";
        my $status;
        if ( $sub_lines[$w] =~ m/$test1/ ) {
          print "yes";
     
          $status = adcon($port_global);
          print " The result is $status\n";
          if ( $status eq "pass" ) {
            print "pass";
            print FILE "$test1=Pass\n";
          }
          else {
            print "fail";
            print FILE "$test1=fail\n";
          }
        }
        my $test2 = "PB002";
        if ( $sub_lines[$w] =~ m/$test2/ ) {
          print "yes";
          do "delete_contact.pl";
          $status = delcon($port_global);
          print " The result is $status\n";
          if ( $status eq "pass" ) {
            print "pass";
            print FILE "$test2=Pass\n";
          }
          else {
            print "fail";
            print FILE "$test2=fail\n";
          }
        }
     
        my $test3 = "PB003";
        if ( $sub_lines[$w] =~ m/$test3/ ) {
          print "yes";
          do "search_name.pl";
          $status = searchname($port_global);
          print " The result is $status\n";
          if ( $status == 0 ) {
            print "pass";
            print FILE "$test3=Pass\n";
          }
          else {
            print "fail";
            print FILE "$test3=fail\n";
          }
     
        }
     
        my $test4 = "PB004";
        if ( $sub_lines[$w] =~ m/$test4/ ) {
          print "yes";
          do "call_contact.pl";
          $status = callcon($port_global);
          print " The result is $status\n";
          if ( $status eq "pass" ) {
            print "pass";
            print FILE "$test4=Pass\n";
          }
          else {
            print "fail";
            print FILE "$test4=fail\n";
          }
     
        }
     
        my $test5 = "PB005";
        if ( $sub_lines[$w] =~ m/$test5/ ) {
          print "yes";
          do "messsage_contact.pl";
          $status = messcon($port_global);
          print "The result is $status\n";
          if ( $status eq "pass" ) {
            print "pass";
            print FILE "$test5=Pass\n";
          }
          else {
            print "fail";
            print FILE "$test5=fail\n";
          }
     
        }
     
      }
     
      close FILE;
     
    }
     
    #================================================
    # Our Unique Thread
    #================================================
    sub WorkThread {
     
      # Around in circles
      while (1) {
     
        # asked the thread to work
        if ( $ThreadWork == 1 ) {
     
          # Launches the process and get the result
          my @Result = $FunctionsToLaunchThread{$FunctionName}->(@ArgumentsThread);
          $RefResultFunction = shared_clone( \@Result );
     
          # asked the thread to sleep
          $ThreadWork = 0;
        }
     
        #Complete thread
        last if ( $KillThread == 1 );
     
        sleep 0.5;
      }
      return;
    }

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut threads
    Salut je résolu le problème de la création du fil. Mais j'ai un nouveau problème.
    Ci-dessous je vais essayer d'expliquer le problème:

    1. J'ai créé un thread pour un sous-programme(procedure)
    2. Dans ce sous-programme que je veux faire une telle déclaration:
    Le fichier Perl est externe.
    3. Je n'ai pas fait ce fichier Perl partagée.
    4. Quand j'appelle ce fil (sous-programme-procedure), le fichier ne s'exécute pas

    Comment puis-je résoudre ce problème? Comment faire de ce fichier Perl comme ils partagés?

    Merci pour votre temps.

  6. #6
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    Peux-tu nous montrer le code ?

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut threads
    C'est la routine pour laquelle j'ai créé le fil.

    Dans le sous-programme que j'appelle ce code do "addcontact.pl", qui n'est pas partagée


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    sub run_script {
     
       
      my $current = localtime(time);
     
      #print "Current date and time is $current";
     
      use POSIX qw(strftime);
      my $now_string = strftime "%d-%b-%Y--%T", localtime;
      print $now_string;
     
      my $str = "$now_string.txt";
      print $str;
      open FILE, "+>>Test_Results/$str" or die $!;
     
      do "addcontact.pl";
     
      
     
    
      use Device::Modem::GSM;
     
      my $modem = new Device::Modem::GSM(
        port     => "/dev/$port_global",
        log      => "file,$now_string.log", );
     
      
    }

  8. #8
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut
    le reste du code est le même que dans le post précédent. Le seul problème, je suis confronté est que je ne suis pas appeler le fichier externe perl dans ce sous-programme. C'est ainsi que pour faire de ce fichier partagé!

  9. #9
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    est censé faire quoi ?
    A quoi correspond le mot do ?
    Lorsque tu enlèves la ligne , est-ce que le reste fonctionne ?

  10. #10
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2011
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Inde

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juillet 2011
    Messages : 6
    Points : 1
    Points
    1
    Par défaut
    le mot do c'est comme use.

    do - c'est une fonction
    require - est également une fonction

    (use = do = require) mais il ya une certaine différence entre les deux


    Oui, il fait le reste du travail mais ne sera pas appeler le do

  11. #11
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 820
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 820
    Points : 499 184
    Points
    499 184
    Par défaut
    do est généralement utilisé pour effectuer des boucles : until et while, néanmoins, on peut l'utiliser comme require; Mais bon, il faut éviter cette façon de programmer, je ne trouve pas ce mode de programmation approprié.

    Pour revenir, à ton souci, si le do charge le contenu du script addcontact.pl, tu te retrouves avec du code Perl non partagé, ce qui ne fonctionnera pas. Il faut donc revoir ton algorithme pour procéder différemment.

Discussions similaires

  1. [langage] threads en Perl
    Par mikygee dans le forum Langage
    Réponses: 10
    Dernier message: 29/11/2006, 23h00
  2. Réponses: 1
    Dernier message: 22/09/2005, 20h39
  3. Thread perl
    Par superjb dans le forum Web
    Réponses: 1
    Dernier message: 12/09/2005, 11h00
  4. [langage] Perl a t'il été compiler avec les threads
    Par vodevil dans le forum Langage
    Réponses: 2
    Dernier message: 07/05/2005, 15h00
  5. [reseaux] Gestion des threads en perl
    Par totox17 dans le forum Programmation et administration système
    Réponses: 2
    Dernier message: 28/11/2002, 09h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo