<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/3469" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2003-01-16T17:43:08-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/3469</id>

		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2003-01-16T17:43:08-04:00</updated>

		<published>2003-01-16T17:43:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=15432#p15432</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=15432#p15432"/>
		<title type="html"><![CDATA[Closing file handles opened by &quot;open&quot;]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=15432#p15432"><![CDATA[
D'oh!  I take it all back... TCL is wonderful.  Thanks for pointing out what I should have seen on my own.  <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_redface.gif" width="15" height="15" alt=":oops:" title="Embarassed"> <br><br><img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><p>Statistics: Posted by Guest — Thu Jan 16, 2003 5:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ppslim]]></name></author>
		<updated>2003-01-16T17:32:28-04:00</updated>

		<published>2003-01-16T17:32:28-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=15431#p15431</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=15431#p15431"/>
		<title type="html"><![CDATA[Closing file handles opened by &quot;open&quot;]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=15431#p15431"><![CDATA[
Yes, Tcl provides the "close" command.<br><br>Your issue is with is with part of the script.<br><div class="codebox"><p>Code: </p><pre><code>proc has_string {file string} {    set file_handle [open $file r]    set lines [split [read $file_handle] "\n"]    foreach line $lines {        if {[regexp "&lt;$string&gt;|Action: $string" $line]} {            return 1        }    }    catch {close $file_handle}    return 0}</code></pre></div>This function looks like it is intended to detect if a logfile has valid information, that could be used as a quote.<br><br>It operates by returning 1 if it does, and 0 if it doesnt.<br><br>However, it returns 1 at the quickest oportunity, without closing the file.<br><br>So for everyfile it checks, that is valid, a new file descriptor is left open.<br><br>Simply add<div class="codebox"><p>Code: </p><pre><code>catch {close $file_handle}</code></pre></div>before the return 1, and you should have all your issues resolved.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2">ppslim</a> — Thu Jan 16, 2003 5:32 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Anonymous]]></name></author>
		<updated>2003-01-16T16:19:05-04:00</updated>

		<published>2003-01-16T16:19:05-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=15426#p15426</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=15426#p15426"/>
		<title type="html"><![CDATA[Closing file handles opened by &quot;open&quot;]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=15426#p15426"><![CDATA[
I've written a random quote script which displays a random quote or action from one of the log files in my eggdrop directory.  The script is here: <br><br><a href="http://www.bludgeon.org/~rayvd/eggdrop/rand_quote.tcl" class="postlink">http://www.bludgeon.org/~rayvd/eggdrop/rand_quote.tcl</a><br><br>The script works great... except that the close function in TCL doesn't appear to actually close the file descriptor opened by "open".  After a lot of people use the !quote feature, too many file descriptors will be open, and the bot will basically hang.  An examination of eggdrop.log shows that the bot is unable to do much of anything because all file handles are in use.  I have verified that the script opens hundreds of file handles (using the Linux 'lsof' command) and the only time at which they are closed is when the parent tcl script is ended (eggdrop).<br><br>Has anyone run into this before?  Is there any work-around, or a way to close file handles without exiting the parent process?  The only semi-solution I can think of is to write the program in an external script and call it from the TCL.  But darnit, I already wrote it all in TCL, why doesn't close just work like it does in every other language?? <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>Ok, thanks!<p>Statistics: Posted by Guest — Thu Jan 16, 2003 4:19 pm</p><hr />
]]></content>
	</entry>
	</feed>
