Jump to content

Too many open files


Recommended Posts

G'day everyone

I've written a script that visits the Wikipedia and extracts some information from it (basically, it creates a bilingual word list). The startfile is a list of words. The endfile is a bilingual list of words. Here it is:

;

#include <File.au3>

$startup = MsgBox (4, "Wikterma 1.1", "Welcome to Wikterma 1.0" & @CRLF & "by Samuel Murray, 2007" & @CRLF & @CRLF & "This program creates a bilingual word list" & @CRLF & "based on interwiki links on the Wikipedia." & @CRLF & @CRLF & "Have you read the readme.txt file?", "")

If $startup = 7 Then Exit

$startfilename = InputBox ("Name of unilingual word list", "Enter the full name of your initial unilingual word list")
$startfile = FileOpen($startfilename, 0)
$lines = _FileCountLines ($startfilename)

$endfilename = InputBox ("Name of bilingual word list", "Enter a name for your final bilingual word list")
$endfile = FileOpen($endfilename, 1)

$language = InputBox ("Target language name", "Enter the target language's name in that language (default is Dutch)", "Nederlands")
$langcode = InputBox ("Target language code", "Enter the target language's language code in lower case (default is Dutch)", "nl")

$sleeptime = InputBox ("(Optional) Sleep time between fetches", "Enter the time in milliseconds that Wikterma should allow for fetching a web page (default is 2 seconds)", "2000")

$traytip = MsgBox (4, "(Optional) See progress?", "Do you want to see the progress as a traytip?")

For $i = 1 to $lines

$targetword1 = "(empty)"

$sourceword = FileReadLine($startfilename, $i)

$wikipage = InetGet("http://en.wikipedia.org/wiki/" & $sourceword, "temp.txt")

$targetword0 = StringRegExp(FileRead(FileOpen('temp.txt', 0)), '(?<=' & $langcode & '\.wikipedia\.org/wiki/).*(?=">' & $language & ')', 1)

If IsArray($targetword0) Then $targetword1 = $targetword0[0]
If IsArray($targetword0) Then FileWriteLine($endfile, $sourceword & " :: " & $targetword1)

If $traytip = 6 Then TrayTip ("Wikterma now parsing...", "Term " & $i & " of " & $lines & ". " & $sourceword & " :: " & $targetword1, 10)

Sleep ($sleeptime)
FileClose ('temp.txt')

Next

MsgBox (0, "Done!", "All done!", 10)

After varying numbers of cycles (sometimes 40, sometimes 100) the script stops with the error message that the maximum number of files are open. AFAIK I do close the file inside the loop. What else can I do? What else can be wrong?

Thanks

Samuel

Link to comment
Share on other sites

Hi,

haven't lookes closer, but I would use _FileReadToArray instead of of FileReadLine ...

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Developers

You cannot close a Filename but need to close the fileHandle as returned by fileopen:

For $i = 1 To $lines
    $targetword1 = "(empty)"
    $sourceword = FileReadLine($startfilename, $i)
    $wikipage = InetGet("http://en.wikipedia.org/wiki/" & $sourceword, "temp.txt")
    $H_TF = FileOpen('temp.txt', 0)
    $targetword0 = StringRegExp(FileRead($H_TF), '(?<=' & $langcode & '\.wikipedia\.org/wiki/).*(?=">' & $language & ')', 1)
    If IsArray($targetword0) Then $targetword1 = $targetword0[0]
    If IsArray($targetword0) Then FileWriteLine($endfile, $sourceword & " :: " & $targetword1)
    If $traytip = 6 Then TrayTip("Wikterma now parsing...", "Term " & $i & " of " & $lines & ". " & $sourceword & " :: " & $targetword1, 10)
    Sleep($sleeptime)
    FileClose($H_TF)
Next

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You cannot close a Filename but need to close the fileHandle as returned by fileopen.

Thanks, JdeB!

Now I just have to figure out why the script doesn't write to the file in real time (it creates an empty file and then only at the end of the script it writes all the stuff to that file). It is as if the script keeps everything in memory and doesn't really write it to the file.

Thanks again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...