Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

The process cannot access the file because it is being used by another process?[Problem disappeared!]

by BrowserUk (Pope)
on Apr 27, 2016 at 21:44 UTC ( #1161700=perlquestion: print w/replies, xml ) Need Help??

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

Update!

Before I posted, I tried a bunch of things and ran it at least a dozen times getting the exact same failure. I the cut the script of the top of the data, renamed the file .dat and stuck the script into a new file of the old name. I changed <DATA> to <> and supplied the data file on the command line and it worked first time.

I've just recreated the all in one script; and now it runs perfectly. I have no explanation for the error or the cure; but I suspect 1nickt called it.

Thanks for your help guys.


I'm getting this error when I try to run the following code:

C:\Motor>parseAns.pl The process cannot access the file because it is being used by another + process.

Another process is accessing the DATA pseudo-handle?

The data is large 2.4 million, but I'm sure I've processed much larger datasets from <DATA> before; and I've commented out the storing of the data to the array, so it isn't running out of memory. Cluebats anyone?

#! perl -slw use strict; my @data; my $i = 0; #$data[ $i++ ] = [ split ' ' ] ++$i while <DATA>; print $i; __DATA__ -69.282032302755084 40.000000000000014 0 -1 -69.123493781255831 39.908467741935496 -1.4443382565142906e-006 -1 -68.748013135538145 40.911009397420145 0 -1 -68.964955259756593 39.816935483870985 -2.990721348858345e-006 -1 -68.370049396495517 40.298149116372635 -6.3944096502804299e-006 -1 -68.202015544462682 41.814890597403163 0 -1 ... 2.4 million lines omitted.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on The process cannot access the file because it is being used by another process?[Problem disappeared!]
  • Select or Download Code

Replies are listed 'Best First'.
Re: The process cannot access the file because it is being used by another process?
by 1nickt (Abbot) on Apr 28, 2016 at 01:01 UTC

    Don't think it's Perl-related and don't think it's referring to DATA. Seems to be a Windows error (see http://tinyurl.com/6q3c6a7 et al.); most solutions appear to involve killing and restarting explorer.exe.

    The way forward always starts with a minimal test.

      To add to this, in my experience, I sometimes found the "preview" pane of Explorer.exe holding open files and thus preventing moving/renaming/overwriting. This does not always happen, and I've used the preview pane to watch images/automatic screenshots being updated. But maybe some other Explorer extension is not as careful with allowing overwriting of files or it is an unfortunate timing issue.

Re: The process cannot access the file because it is being used by another process?
by syphilis (Bishop) on Apr 28, 2016 at 01:19 UTC
    Another process is accessing the DATA pseudo-handle?

    There's an answer on SO pointing out that it doesn't have to be a different process. I don't know if there's anything in that answer that would prove helpful.

    I can't reproduce your problem, btw.
    I generated a test file thusly:
    use warnings; open WR, '>', 'buk.pl' or die $!; print WR "#! perl -slw\n", "use strict;\n\n", "my \@data;\n", "my \$i = 0;\n\n", "#\$data[ \$i++ ] = [ split ' ' ]\n\n", "++\$i while <DATA>;\n\n", "print \$i;\n\n", "__DATA__\n\n"; for(1 .. 500000) { print WR "-69.282032302755084 40.000000000000014 0 -1\n", "-69.123493781255831 39.908467741935496 -1.4443382565142906e-006 + -1\n", "-68.748013135538145 40.911009397420145 0 -1\n", "-68.964955259756593 39.816935483870985 -2.990721348858345e-006 -1\ +n", "-68.370049396495517 40.298149116372635 -6.3944096502804299e-006 + -1\n", "-68.202015544462682 41.814890597403163 0 -1\n"; }
    And then ran the generated perl script (on 32-bit perl-5.16.0 and 64-bit perl-5.22.0), Windows 7:
    C:\_32\pscrpt>perl buk.pl 3000001
    Cheers,
    Rob
Re: The process cannot access the file because it is being used by another process?
by graff (Chancellor) on Apr 28, 2016 at 02:21 UTC
    I'm afraid I don't understand what you gain by having 2.4 million lines of data attached as part of the perl script. Have you really not tried putting those first 13 lines into a separate file, so that the 2.4 million lines of data can sit alone (without the script attached) in a separate file, which your separate perl script then reads "in the normal way"?

    Apart from that, it wouldn't surprise me to learn that a "modern" windows OS is still having (or making) trouble when more than one process wants to open the same file, and one of those processes wants write access on the file.

    (Have you tried putting print "starting now\n"; as the 3rd line, to see if you get any output at all before the error message?)

      Have you really not tried putting those first 13 lines into a separate file, ...

      Of course, that exactly what I did. I posted the error because I've never encountered it before and wondered if anyone knew what caused it.

      As for the why. Why do you ever put DATA in a script? Same reasons apply.

      For the specifics of this occasion. I'd just copied the data out of another much bigger file with mixed content -- rather than write what would be a moderately complex parser -- to see what if any sense I could make of it. It was sat in the paste buffer when I opened a new file in my editor to write my scratch script and thought, why bother with a separate file...

      Then the error occurred and the rest you see here.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: The process cannot access the file because it is being used by another process?
by Marshall (Canon) on Apr 28, 2016 at 02:07 UTC
    I have also been unable to replicate this on my Win XP laptop. This appears to be some kind of weird Windows problem. The "answer" may some some kind of kludge that sets Window's brain straight? The DATA handle is a weird critter that is essentially a file handle to the current .pl program at a particular byte offset. I am wondering if you are able to seek (DATA,0,0) or die "seek failed $!"; prior to reading from DATA? This trick allows a Perl program to read itself. This might help "un-confuse" the file system, but because I can't replicate the problem, I have no way to test this. It is for sure a weird idea that shouldn't matter, but it might. oh, I'm using Perl 5.22 on a Win XP laptop.
Re: The process cannot access the file because it is being used by another process?[Problem disappeared!]
by Discipulus (Abbot) on Apr 28, 2016 at 07:42 UTC
    Not reproducible errors are mmhh.. how to say? just weird happenings?

    Googgling the error text you received leads to many different things or probably weird behaviour of explorer.exe

    In my experience windows error reporting is not the best things here around.

    Speaking of more than 150 Mb of DATA other things can also lock the file: for example antivirus and the indexer service come to mind, maybe in conjunction with some IO temporary issue.

    L*

    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.
      other things can also lock the file

      I think I may know the cause; though a half-hearted attempt to reproduce it failed.

      I had the original file from which I cut the data which is 350MB; and I had 2.4 million numbers pasted into the program file in the same editor; I also have a simulation running that is using 3.2GB of my 8GB. And of course, windows had to store the paste buffer copy somewhere also.

      I saved the file from the editor, switched to the command line and tried to run it. I didn't wait or check to see if the editor had finished saving it to disk. That could mean that the editor was still trying to write the file out whilst I was trying to run the script.

      However, I also switched back into the editor and made some changes, before trying again with the same result. Now normally speaking the editor wouldn't allow me to edit the file if it was still in the process of saving it; so how could that be?

      But maybe, it completed just as I switched back to it. And then when I saved the changes and tried again the problem repeats. But for that to happens again and again seems like extremely unfortunate (some might say incredible) timing; until I remembered that Windows gives the (newly) foreground process a priority boost when you switch to it.

      It is just possible that with two of four cores currently fully utilised to running the background simulation; and system memory tight; the editor was being exceptionally slow writing the large file to disk, through a severely depleted system cache. With a busy system; depleted cache and me switching away to the command line thus giving it the priority boost; the editor was simply starved of cycles until I switched back to it each time when it got the boost and completed.

      Anyhoo; that's what I'm going to put it down to; and promptly forget about it. I've got too much on to pursue it any further.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re: The process cannot access the file because it is being used by another process?
by Anonymous Monk on Apr 27, 2016 at 22:02 UTC
      FWIW, I get nothing like that using v5.8.9 and v5.16.1 on win32

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1161700]
Front-paged by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2021-04-22 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?