ktats****@users*****
ktats****@users*****
2011年 2月 8日 (火) 16:47:26 JST
Index: docs/modules/Parallel-ForkManager-0.7.5/ForkManager.pod diff -u docs/modules/Parallel-ForkManager-0.7.5/ForkManager.pod:1.3 docs/modules/Parallel-ForkManager-0.7.5/ForkManager.pod:1.4 --- docs/modules/Parallel-ForkManager-0.7.5/ForkManager.pod:1.3 Mon May 30 22:54:09 2005 +++ docs/modules/Parallel-ForkManager-0.7.5/ForkManager.pod Tue Feb 8 16:47:26 2011 @@ -2,8 +2,12 @@ =head1 åå +=begin original + Parallel::ForkManager - A simple parallel processing fork manager +=end original + Parallel::ForkManager - ç°¡åãªä¸¦åå¦çã«ããforkããã¼ã¸ã£ã¼ =head1 æ¦è¦ @@ -24,16 +28,24 @@ =head1 説æ +=begin original + This module is intended for use in operations that can be done in parallel where the number of processes to be forked off should be limited. Typical use is a downloader which will be retrieving hundreds/thousands of files. +=end original + ãã®ã¢ã¸ã¥ã¼ã«ã¯ç¨¼åä¸ã«ããã¦ä¸¦åå¦çããããã¨ãæå³ãã¦ãã. ãã®é,ããã»ã¹ã®åå²æ°ã¯å¶éãããã¹ããã®ã§ãã. å ¸åçãªä½¿ããæ¹ã¨ãã¦ã¯ãã¡ã¤ã«ã®æ°ç¾/æ°åãåå¾ãããã¦ã³ãã¼ãã¼ã¨ãã¦ã§ãã. +=begin original + The code for a downloader would look something like this: +=end original + ãã¦ã³ãã¼ãã¼ã®ã³ã¼ãã¨ãã¦ã¯ãã®ããã«ãªãã§ããã: @@ -67,33 +79,49 @@ } $pm->wait_all_children; +=begin original + First you need to instantiate the ForkManager with the "new" constructor. You must specify the maximum number of processes to be created. If you specify 0, then NO fork will be done; this is good for debugging purposes. +=end original + ã¾ãåãã«ForkManagerã®"new"ã³ã³ã¹ãã©ã¯ã¿ãå ·ä½åããå¿ è¦ãããã¾ã. ã³ã³ã¹ãã©ã¯ã¿ãä½æããéã«ãããã»ã¹æ°ã®æ大å¤ãæå®ããªããã°ãªãã¾ãã. ããããã»ã¹æ°ã0ã¨æå®ããå ´åã¯forkã¯ãããªãã§ããã;ããã¯ãããã°ãè¡ãçºã®ããæ¹æ³ã§ã. +=begin original + Next, use $pm->start to do the fork. $pm returns 0 for the child process, and child pid for the parent process (see also L<perlfunc(1p)/fork()>). The "and next" skips the internal loop in the parent process. NOTE: $pm->start dies if the fork fails. +=end original + 次ã«,forkããçºã«$pm->startã使ãã¾ã. $pmã¯åããã»ã¹ã®çºã«0ã«ãè¿ã, 親ããã»ã¹ã®çºã«åpidãè¿ãã¾ã (ã¾ãã¯ã L<perlfunc(1p)/fork()>ãè¦ã¦ä¸ãã). "and next"ã¯è¦ªããã»ã¹ã«ãããå é¨ã®ç¹°ãè¿ããã¹ããããã¾ã. 注æ: $pm->startã¯forkã失æããã°æ»ã«ã¾ã. +=begin original + $pm->finish terminates the child process (assuming a fork was done in the "start"). +=end original + $pm->finishã¯åããã»ã¹ãçµäºããã¾ã ("start"ã§forkãéå§ããã¨ä»®å®ããå ´å). +=begin original + NOTE: You cannot use $pm->start if you are already in the child process. If you want to manage another set of subprocesses in the child process, you must instantiate another Parallel::ForkManager object! +=end original + 注æ:ããªãããã§ã«åããã»ã¹ã«å± ãã®ãªãã°ã$pm->startã使ããã¨ã¯ã§ãã¾ãã. åããã»ã¹ããã1ã»ããããµãããã»ã¹ã¨ãã¦ç®¡çãããã®ãªãã°, å¥ã®Parallel::ForkManagerãªãã¸ã§ã¯ããå ·ä½åããå¿ è¦ãããã¾ã. @@ -104,10 +132,14 @@ =item new $processes +=begin original + Instantiate a new Parallel::ForkManager object. You must specify the maximum number of children to fork off. If you specify 0 (zero), then no children will be forked. This is intended for debugging purposes. +=end original + æ°ããParallel::ForkManagerãªãã¸ã§ã¯ããå ·ä½åãã¾ã. åããã»ã¹ãåå²ãããæ大æ°ãæå®ããªããã°ãªãã¾ãã. 0ãæå®ããå ´åã¯åå²ãããåã¯ããã¾ãã. @@ -115,32 +147,44 @@ =item start [ $process_identifier ] +=begin original + This method does the fork. It returns the pid of the child process for the parent, and 0 for the child process. If the $processes parameter for the constructor is 0 then, assuming you're in the child process, $pm->start simply returns 0. +=end original + ãã®ã¡ã½ããã¯forkãå®è¡ãã¾ã. åããã»ã¹ã®pidã親ããã»ã¹ã«è¿ã,åããã»ã¹ã«ã¯0ãè¿ãã¾ã. $processesãã©ã¡ã¼ã¿ãã³ã³ã¹ãã©ã¯ã¿ã«0ã¨ãã¦æ¸¡ãããå ´å, ããªãããã§ã«åããã»ã¹ã«å± ãã¨ä»®å®ãã, $pm->startã¯åã«0ãè¿ãã¾ã. +=begin original + An optional $process_identifier can be provided to this method... It is used by the "run_on_finish" callback (see CALLBACKS) for identifying the finished process. +=end original + ä»»æã§$process_identifierï¼ããã»ã¹èå¥åï¼ãã¡ã½ããã«æä¾ãããã¨ãã§ãã¾ã... ããã¯"run_on_finish"ã§çµäºããããã»ã¹ãç¹å®ãååããçºã«ä½¿ããã¾ã. (CALLBACKSã®é ç®ãè¦ã¦ä¸ãã) =item finish [ $exit_code ] +=begin original + Closes the child process by exiting and accepts an optional exit code (default exit code is 0) which can be retrieved in the parent via callback. If you use the program in debug mode ($processes == 0), this method doesn't do anything. +=end original + 親ããã»ã¹ãååã®éã«åå¾ã§ããããã«åããã»ã¹ãéããçºã«çµäºãçµäºã®çºã®ã³ã¼ããåãå ¥ãã¾ã. (è¦å®ã® çµäºã³ã¼ã㯠0 ã§ã) ãã®ããã°ã©ã ããããã°ã¢ã¼ãã§ä½¿ç¨ããå ´å ($processes == 0 ã®å ´å), @@ -148,17 +192,25 @@ =item set_max_procs $processes +=begin original + Allows you to set a new maximum number of children to maintain. Returns the previous setting. +=end original + æ°ããåããã»ã¹æ°ã®æ大å¤ãè¨å®ãããã¨ãã§ãã¾ã. ååã®è¨å®ãè¿ããã¾ã.ï¼å®éã«ã¯ä»åè¨å®ããå¤ãè¿ããã¾ãï¼ =item wait_all_children +=begin original + You can call this method to wait for all the processes which have been forked. This is a blocking wait. +=end original + forkãããå ¨ã¦ã®åããã»ã¹ãå¾ ã¤çºã«ãã®ã¡ã½ãããå¼ã¶ãã¨ãã§ãã¾ã. ããã¯å¾ ã¡ã妨ãã¾ã. @@ -166,28 +218,44 @@ =head1 CALLBACKS +=begin original + You can define callbacks in the code, which are called on events like starting a process or upon finish. +=end original + ããã»ã¹ã®éå§æã¾ãã¯çµäºæã®ã¤ãã³ãã®ãå¼ã°ããã¨ãã« ã³ã¼ãã®ä¸ã«ååãå®ç¾©ãããã¨ãã§ãã¾ã. +=begin original + The callbacks can be defined with the following methods: +=end original + ååã¯ä»¥ä¸ã®ã¡ã½ããã§å®ç¾©ãããã¨ãã§ãã¾ã: =over 4 =item run_on_finish $code [, $pid ] +=begin original + You can define a subroutine which is called when a child is terminated. It is called in the parent process. +=end original + åããã»ã¹ãçµäºããéã«å¼ã°ãããµãã«ã¼ãã³ãå®ç¾©ãããã¨ãã§ãã¾ã. ããã¯è¦ªããã»ã¹ããå¼ã°ãã¾ã. +=begin original + The paremeters of the $code are the following: +=end original + $codeã®ãã©ã¡ã¼ã¿ã¯ä»¥ä¸ã§ã: - pid of the process, which is terminated @@ -203,14 +271,22 @@ =item run_on_start $code +=begin original + You can define a subroutine which is called when a child is started. It called after the successful startup of a child in the parent process. +=end original + åããã»ã¹ãéå§ããéã«å¼ã°ãããµãã«ã¼ãã³ãå®ç¾©ãããã¨ãã§ãã¾ã. 親ããã»ã¹ã®ä¸ã§åããã»ã¹ãæ£å¸¸ã«éå§ãããå¾ã«å¼ã°ãã¾ã. +=begin original + The parameters of the $code are the following: +=end original + $codeã®ãã©ã¡ã¼ã¿ã¯ä»¥ä¸ã§ã: - pid of the process which has been started @@ -220,6 +296,8 @@ =item run_on_wait $code, [$period] +=begin original + You can define a subroutine which is called when the child process needs to wait for the startup. If $period is not defined, then one call is done per child. If $period is defined, then $code is called periodically and the @@ -228,6 +306,8 @@ signals can shorten and the process scheduler can make it longer (on busy systems). +=end original + åããã»ã¹ãéå§æã«å¾ ã¡ãå¿ è¦ã¨ããå ´åã«å¼ã°ãããµãã«ã¼ãã³ãå®ç¾©ãããã¨ãã§ãã¾ã. $periodãå®ç¾©ããã¦ããªãå ´å,ä¸ã¤ã®åããã»ã¹åä½ã§å¼ã³ã¾ã. $periodãå®ç¾©ããã¦ããå ´å,$codeã¯å®æçã«å¼ã°ã,ã¢ã¸ã¥ã¼ã«ã¯$periodç§ã®éã« @@ -236,12 +316,20 @@ æ£ç¢ºãª"$period seconds"ã§ãããã¨ã¯ä¿éãã¾ãã, ã·ã°ãã«ã¯ç縮ãããã¨ãã§ã,ããã»ã¹ã¹ã±ã¸ã¥ã¼ã©ã¼ã§ã¯é·ããããã¨ãã§ãã¾ã (å¿ããã·ã¹ãã ã§ã¯). +=begin original + The $code called in the "start" and the "wait_all_children" method also. +=end original + $codeã¯"start"ã"wait_all_children"ã¡ã½ããã«ããå¼ã¶ãã¨ãã§ãã. +=begin original + No parameters are passed to the $code on the call. +=end original + ãã©ã¡ã¼ã¿ããªãå ´åã¯å¼ã³åºãã®éã«$codeã¯ãã¹ãããã¨ãã§ãã. =back @@ -250,8 +338,12 @@ =head2 Parallel get +=begin original + This small example can be used to get URLs in parallel. +=end original + 並åçã«URLãåå¾ããçºã«ä½¿ç¨ãããç°¡åãªä¾ã§ã. use Parallel::ForkManager; @@ -273,8 +365,12 @@ =head2 Callbacks +=begin original + Example of a program using callbacks to get child exit codes: +=end original + åããã»ã¹ãã®çµäºã³ã¼ããååããã®ã使ç¨ããå ´åã®ä¾ã§ã: use strict; @@ -327,24 +423,36 @@ =head1 ã㰠㨠å¶é +=begin original + Do not use Parallel::ForkManager in an environment, where other child processes can affect the run of the main program, so using this module is not recommended in an environment where fork() / wait() is already used. +=end original + Parallel::ForkManagerã¯ãã®ãããªç°å¢ã§ã¯ä½¿ããã¨ãã§ãã¾ãã, å¥ã®åããã»ã¹ãã¡ã¤ã³ããã°ã©ã ã«å½±é¿ãä¸ããå ´å, ãããã£ã¦ãã®ã¢ã¸ã¥ã¼ã«ã使ç¨ããã®ã¯fork() / wait()ãæ¢ã«ä½¿ç¨ãããç°å¢ã§æ¨è¦ããã¾ããã +=begin original + If you want to use more than one copies of the Parallel::ForkManager, then you have to make sure that all children processes are terminated, before you use the second object in the main program. +=end original + ä¸ã¤ä»¥ä¸ã®Parallel::ForkManagerã使ç¨ãããå ´å,主ããã°ã©ã ã§ç¬¬äºã®ãªãã¸ã§ã¯ãã使ç¨ããåã«, å ¨ã¦ã®åããã»ã¹ãçµäºããã®ã確å®ã«ããªããã°ãªãã¾ãã, +=begin original + You are free to use a new copy of Parallel::ForkManager in the child processes, although I don't think it makes sense. +=end original + ããªãã¯åããã»ã¹ã«èªç±ã«Parallel::ForkManagerã®æ°ããã³ãã¼ã使ç¨ãããã¨ãã§ãã¾ã, ç§ã¯ãããç解ã§ããã¨ã¯æãã¾ããã.