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

Hello All, We frequently get an error message saying 'can't spawn nowait': Resource Temporary Unavailable. The script runs on NT and this error happens only when running against large number of files (almost 1800 files). I'm looking for more information on Spawning on NT and if there are known limitation to consider. Thanks

Replies are listed 'Best First'.
(tye)Re: 'can't spawn nowait'
by tye (Sage) on Oct 29, 2001 at 22:59 UTC

    I couldn't find that error message. However, I did find the following. Win32 Perl's code says:

    switch(mode) { case P_NOWAIT: /* asynch + remember result */ if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) { errno = EAGAIN; ret = -1; goto RETVAL; }
    which means that you can't spawn more than 64 children that you aren't going to immediately wait for.

    This is so that emulation of wait/waitpid can be accomplished using

    /* if a child exists, wait for it to die */ waitcode = WaitForMultipleObjects(w32_num_children, w32_child_handles, FALSE, INFINITE);
    where the w32_child_handles array is added to each time a "nowait" child is spawned.

    Children are removed from this list when you wait/waitpid for them. Unfortunately, at least in Perl 5.6.0 and earlier, WNOHANG() is ignored by Win32 Perl's waitpid. In some ways, this is rather trivial to patch. But getting WNOHANG defined in all of the proper places is a bit of a pain.

    If this is the source of your problem, than two work-arounds come to mind. First, you could use Win32::Process to create these children that you don't want to wait for. Second, you could use system("start ...") to throw the "..." command into the background.

            - tye (but my friends call me "Tye")
Re: 'can't spawn nowait'
by slayven (Pilgrim) on Oct 29, 2001 at 23:03 UTC
    groups.google.com returned this on a search for can't spawn nowait

    I actually just figured this out about an hour ago.  Add 
    
    waitpid $pid, 0;
    
    to your script when you are done with each individual call 
    to IO::Pipe.  That frees up the resource that is hanging 
    onto a dead process.open2 can only handle a limited number 
    of processes (128 or 64), so you have to unleash the process 
    by waiting for it to close itself (waitpid).
    
    HTH
    slayven
      Hi Please tell where i put waitpid $pid, 0; I am getting the error CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are: perl1 validate done. perl1 Starting load. perl1 starting JVM... perl1 client/server mode D:\jdk1.5.0_12\bin\java.exeperl1 JVM owner exiting... Can't exec JVM: open3: IO::Pipe: Can't spawn-NOWAIT: No such file or directory at C:/Perl/site/lib/Inline/Java/JVM.pm line 157 at C:/Perl/site/lib/Inline/Java.pm line 408 BEGIN failed--compilation aborted at Sfa/PostLib.pm line 79. Compilation failed in require at c:\inetpub\wwwroot\TestMoto.pl line 4. BEGIN failed--compilation aborted at c:\inetpub\wwwroot\TestMoto.pl line