[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-dev] [GSoC] APAF Report



> I've also installed python and twisted on my android phone, but
> psutils, a dependency of txtorcon, is a wall for porting apaf into
> android.

Hi Michele. It looks like txtorcon is trying to make psutil an
optional dependency...

txtorcon/util.py
 31 try:
 32     import psutil
 33     process_factory = psutil.Process
 34 except ImportError:
 35     process_factory = int
  ...
 82 def process_from_address(addr, port, torstate=None):
  ...
 91     If psutil isn't installed, the PIDs are returned instead of
 92     psutil.Process instances.

Though torstate.py doesn't have this sort of fallback...

txtorcon/torstate.py
  2 import psutil
  ...
292     def guess_tor_pid(self, *args):
293         if self.protocol.is_owned:
294             self.tor_pid = self.protocol.is_owned
295
296         else:
297             self.tor_pid = 0
298             try:
299                 procs = filter(lambda x: x.name.startswith(self.tor_binary),
300                                psutil.get_process_list())
301                 if len(procs) == 1:
302                     self.tor_pid = procs[0].pid
303             except psutil.AccessDenied:
304                 pass

Considering that the method's name is "guess_tor_pid" it sounds like
it should be best-effort, and fail gracefully if psutil is
unavailable. It might be worth asking if this is a bug.

Personally I decided to write my own modules for this functionality
[1] (including some improvements based on psutil [2]) because a C
module dependency didn't feel worth this functionality - especially
since pid lookup is a one-time thing, and doesn't need to be blazingly
fast.

Cheers! -Damian

[1] https://gitweb.torproject.org/stem.git/blob/HEAD:/stem/util/system.py
[2] https://gitweb.torproject.org/stem.git/blob/HEAD:/stem/util/proc.py
_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev