commit 43b7f652ecd91b72c817f2f4fda98a3bf2b97dcd Author: Damian Johnson atagar@torproject.org Date: Sun Jan 26 19:42:30 2014 -0800
Moving get_my_file_descriptor_usage to header panel
The sole user of tor_tools' get_my_file_descriptor_usage() is the header panel. This is functionality that doesn't belong in stem, so might as well move it to its caller. --- arm/header_panel.py | 21 +++++++++++++++++++-- arm/util/tor_tools.py | 32 +------------------------------- 2 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/arm/header_panel.py b/arm/header_panel.py index f287d81..fbd3d92 100644 --- a/arm/header_panel.py +++ b/arm/header_panel.py @@ -23,7 +23,7 @@ import arm.util.tracker
from stem import Signal from stem.control import State -from stem.util import conf, log, str_tools +from stem.util import conf, log, proc, str_tools
import arm.starter import arm.popups @@ -635,7 +635,7 @@ class HeaderPanel(panel.Panel, threading.Thread): # current usage) then omit file descriptor functionality.
if self.vals["tor/fd_limit"]: - fd_used = tor_tools.get_conn().get_my_file_descriptor_usage() + fd_used = get_file_descriptor_usage(controller.get_pid(None))
if fd_used and fd_used <= self.vals["tor/fd_limit"]: self.vals["tor/fd_used"] = fd_used @@ -678,3 +678,20 @@ class HeaderPanel(panel.Panel, threading.Thread):
self._last_update = current_time self.vals_lock.release() + + +def get_file_descriptor_usage(pid): + """ + Provides the number of file descriptors currently being used by this + process. This returns None if this can't be determined. + """ + + # The file descriptor usage is the size of the '/proc/<pid>/fd' contents + # http://linuxshellaccount.blogspot.com/2008/06/finding-number-of-open-file-de... + # I'm not sure about other platforms (like BSD) so erroring out there. + + if pid and proc.is_available(): + try: + return len(os.listdir('/proc/%s/fd' % pid)) + except: + return None diff --git a/arm/util/tor_tools.py b/arm/util/tor_tools.py index 1d17905..87033c9 100644 --- a/arm/util/tor_tools.py +++ b/arm/util/tor_tools.py @@ -3,15 +3,12 @@ Helper for working with an active tor process. This both provides a wrapper for accessing stem and notifications of state changes to subscribers. """
-import math -import os import threading -import time
import stem import stem.control
-from stem.util import log, proc, system +from stem.util import log, system
CONTROLLER = None # singleton Controller instance
@@ -457,33 +454,6 @@ class Controller:
return self.controller.get_user(None)
- def get_my_file_descriptor_usage(self): - """ - Provides the number of file descriptors currently being used by this - process. This returns None if this can't be determined. - """ - - # The file descriptor usage is the size of the '/proc/<pid>/fd' contents - # http://linuxshellaccount.blogspot.com/2008/06/finding-number-of-open-file-de... - # I'm not sure about other platforms (like BSD) so erroring out there. - - self.conn_lock.acquire() - - result = None - - if self.is_alive() and proc.is_available(): - my_pid = self.controller.get_pid(None) - - if my_pid: - try: - result = len(os.listdir("/proc/%s/fd" % my_pid)) - except: - pass - - self.conn_lock.release() - - return result - def get_start_time(self): """ Provides the unix time for when the tor process first started. If this
tor-commits@lists.torproject.org