Too many open files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Too many open files

Omar Lakkis
This may be more of an OS question ...
I have this call

r = get.hist.quote(symbol, start= format(start, "%Y-%m-%d"), end=
format(end, "%Y-%m-%d"))
which does a url request

in a loop and my program runs out of file handlers after few hundred
rotations. The error message is:  'Too many open files'. Other than
increasing the file handlers assigned to my process, is there a way to
cleanly release and reuse these connections?

I run on Mac OS X

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Too many open files

Seth Falcon-2
"Omar Lakkis" <[hidden email]> writes:

> This may be more of an OS question ...
> I have this call
>
> r = get.hist.quote(symbol, start= format(start, "%Y-%m-%d"), end=
> format(end, "%Y-%m-%d"))
> which does a url request
>
> in a loop and my program runs out of file handlers after few hundred
> rotations. The error message is:  'Too many open files'. Other than
> increasing the file handlers assigned to my process, is there a way to
> cleanly release and reuse these connections?

Inside your loop you need to close the connection object created by
url().

for (i in 1:500) {
    con <- url(urls[i])
    ## ... stuff here ...
    close(con)
}

R only allows you to have a fixed number of open connections at one
time, and they do not get closed automatically when they go out of
scope.  These commands may help make clear how things work...

> showConnections()
     description class mode text isopen can read can write
> f = url("http://www.r-project.org", open="r")
> showConnections()
  description                class mode text   isopen   can read can write
3 "http://www.r-project.org" "url" "r"  "text" "opened" "yes"    "no"    
> rm(f)
> showConnections()
  description                class mode text   isopen   can read can write
3 "http://www.r-project.org" "url" "r"  "text" "opened" "yes"    "no"    
> f <- getConnection(3)
> close(f)
> f
Error in summary.connection(x) : invalid connection
> showConnections()
     description class mode text isopen can read can write
>

+ seth

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Too many open files

Gabor Grothendieck
In reply to this post by Omar Lakkis
Try closeAllConnections()

On 5/26/06, Omar Lakkis <[hidden email]> wrote:

> This may be more of an OS question ...
> I have this call
>
> r = get.hist.quote(symbol, start= format(start, "%Y-%m-%d"), end=
> format(end, "%Y-%m-%d"))
> which does a url request
>
> in a loop and my program runs out of file handlers after few hundred
> rotations. The error message is:  'Too many open files'. Other than
> increasing the file handlers assigned to my process, is there a way to
> cleanly release and reuse these connections?
>
> I run on Mac OS X
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Loading...