<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Tor Process — Stem 1.1.0 documentation</title> <link rel="stylesheet" href="../_static/haiku.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/print.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.1.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/theme_extras.js"></script> <link rel="shortcut icon" href="../_static/favicon.png"/> <link rel="top" title="Stem 1.1.0 documentation" href="../index.html" /> <link rel="up" title="Contents" href="../contents.html" /> <link rel="next" title="Controller Responses" href="response.html" /> <link rel="prev" title="Control Socket" href="socket.html" /> </head> <body> <div class="header"><img class="rightlogo" src="../_static/logo.png" alt="Logo"/><h1 class="heading"><a href="../index.html"> <span>Stem Docs</span></a></h1> <h2 class="heading"><span>Tor Process</span></h2> </div> <div class="topnav"> <p> <ul id="navbar"> <li><a href="../index.html">Home</a></li> <li><a href="../tutorials.html">Tutorials</a> <ul> <li><a href="../tutorials/the_little_relay_that_could.html">Hello World</a></li> <li><a href="../tutorials/to_russia_with_love.html">Client Usage</a></li> <li><a href="../tutorials/tortoise_and_the_hare.html">Event Listening</a></li> <li><a href="../tutorials/mirror_mirror_on_the_wall.html">Tor Descriptors</a></li> <li><a href="../tutorials/east_of_the_sun.html">Utilities</a></li> <li><a href="../tutorials/double_double_toil_and_trouble.html">Examples</a></li> </ul> </li> <li><a href="../api.html">API</a> <ul> <li><a href="control.html">stem.control</a></li> <li><a href="connection.html">stem.connection</a></li> <li><a href="socket.html">stem.socket</a></li> <li><a href="#">stem.process</a></li> <li><a href="response.html">stem.response</a></li> <li><a href="exit_policy.html">stem.exit_policy</a></li> <li><a href="version.html">stem.version</a></li> <li><a href="../api.html#descriptors">Descriptors</a></li> <li><a href="../api.html#utilities">Utilities</a></li> </ul> </li> <li><a href="https://trac.torproject.org/projects/tor/wiki/doc/stem">Development</a> <ul> <li><a href="../faq.html">FAQ</a></li> <li><a href="../change_log.html">Change Log</a></li> <li><a href="https://trac.torproject.org/projects/tor/wiki/doc/stem/bugs">Bug Tracker</a></li> <li><a href="../download.html">Download</a></li> </ul> </li> </ul> </p> </div> <div class="content"> <div class="section" id="module-stem.process"> <span id="tor-process"></span><h1>Tor Process<a class="headerlink" href="#module-stem.process" title="Permalink to this headline">¶</a></h1> <p>Helper functions for working with tor as a process.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">NO_TORRC:</th><td class="field-body">when provided as a torrc_path tor is ran with a blank configuration</td> </tr> <tr class="field-even field"><th class="field-name" colspan="2">DEFAULT_INIT_TIMEOUT:</th></tr> <tr class="field-even field"><td> </td><td class="field-body">number of seconds before we time out our attempt to start a tor instance</td> </tr> </tbody> </table> <p><strong>Module Overview:</strong></p> <div class="highlight-python"><pre>launch_tor - starts up a tor process launch_tor_with_config - starts a tor process with a custom torrc</pre> </div> <dl class="function"> <dt id="stem.process.launch_tor"> <tt class="descclassname">stem.process.</tt><tt class="descname">launch_tor</tt><big>(</big><em>tor_cmd='tor'</em>, <em>args=None</em>, <em>torrc_path=None</em>, <em>completion_percent=100</em>, <em>init_msg_handler=None</em>, <em>timeout=90</em>, <em>take_ownership=False</em><big>)</big><a class="reference internal" href="../_modules/stem/process.html#launch_tor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#stem.process.launch_tor" title="Permalink to this definition">¶</a></dt> <dd><p>Initializes a tor process. This blocks until initialization completes or we error out.</p> <p>If tor’s data directory is missing or stale then bootstrapping will include making several requests to the directory authorities which can take a little while. Usually this is done in 50 seconds or so, but occasionally calls seem to get stuck, taking well over the default timeout.</p> <p><strong>To work to must log at NOTICE runlevel to stdout.</strong> It does this by default, but if you have a ‘Log’ entry in your torrc then you’ll also need ‘Log NOTICE stdout’.</p> <p>Note: The timeout argument does not work on Windows, and relies on the global state of the signal module.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>tor_cmd</strong> (<em>str</em>) – command for starting tor</li> <li><strong>args</strong> (<em>list</em>) – additional arguments for tor</li> <li><strong>torrc_path</strong> (<em>str</em>) – location of the torrc for us to use</li> <li><strong>completion_percent</strong> (<em>int</em>) – percent of bootstrap completion at which this’ll return</li> <li><strong>init_msg_handler</strong> (<em>functor</em>) – optional functor that will be provided with tor’s initialization stdout as we get it</li> <li><strong>timeout</strong> (<em>int</em>) – time after which the attempt to start tor is aborted, no timeouts are applied if <strong>None</strong></li> <li><strong>take_ownership</strong> (<em>bool</em>) – asserts ownership over the tor process so it aborts if this python process terminates or a <a class="reference internal" href="control.html#stem.control.Controller" title="stem.control.Controller"><tt class="xref py py-class docutils literal"><span class="pre">Controller</span></tt></a> we establish to it disconnects</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>subprocess.Popen</strong> instance for the tor subprocess</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Raises :</th><td class="field-body"><p class="first last"><strong>OSError</strong> if we either fail to create the tor process or reached a timeout without success</p> </td> </tr> </tbody> </table> </dd></dl> <dl class="function"> <dt id="stem.process.launch_tor_with_config"> <tt class="descclassname">stem.process.</tt><tt class="descname">launch_tor_with_config</tt><big>(</big><em>config</em>, <em>tor_cmd='tor'</em>, <em>completion_percent=100</em>, <em>init_msg_handler=None</em>, <em>timeout=90</em>, <em>take_ownership=False</em><big>)</big><a class="reference internal" href="../_modules/stem/process.html#launch_tor_with_config"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#stem.process.launch_tor_with_config" title="Permalink to this definition">¶</a></dt> <dd><p>Initializes a tor process, like <a class="reference internal" href="#stem.process.launch_tor" title="stem.process.launch_tor"><tt class="xref py py-func docutils literal"><span class="pre">launch_tor()</span></tt></a>, but with a customized configuration. This writes a temporary torrc to disk, launches tor, then deletes the torrc.</p> <p>For example...</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">tor_process</span> <span class="o">=</span> <span class="n">stem</span><span class="o">.</span><span class="n">process</span><span class="o">.</span><span class="n">launch_tor_with_config</span><span class="p">(</span> <span class="n">config</span> <span class="o">=</span> <span class="p">{</span> <span class="s">'ControlPort'</span><span class="p">:</span> <span class="s">'2778'</span><span class="p">,</span> <span class="s">'Log'</span><span class="p">:</span> <span class="p">[</span> <span class="s">'NOTICE stdout'</span><span class="p">,</span> <span class="s">'ERR file /tmp/tor_error_log'</span><span class="p">,</span> <span class="p">],</span> <span class="p">},</span> <span class="p">)</span> </pre></div> </div> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>config</strong> (<em>dict</em>) – configuration options, such as ‘{“ControlPort”: “9051”}’, values can either be a <strong>str</strong> or <strong>list of str</strong> if for multiple values</li> <li><strong>tor_cmd</strong> (<em>str</em>) – command for starting tor</li> <li><strong>completion_percent</strong> (<em>int</em>) – percent of bootstrap completion at which this’ll return</li> <li><strong>init_msg_handler</strong> (<em>functor</em>) – optional functor that will be provided with tor’s initialization stdout as we get it</li> <li><strong>timeout</strong> (<em>int</em>) – time after which the attempt to start tor is aborted, no timeouts are applied if <strong>None</strong></li> <li><strong>take_ownership</strong> (<em>bool</em>) – asserts ownership over the tor process so it aborts if this python process terminates or a <a class="reference internal" href="control.html#stem.control.Controller" title="stem.control.Controller"><tt class="xref py py-class docutils literal"><span class="pre">Controller</span></tt></a> we establish to it disconnects</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><strong>subprocess.Popen</strong> instance for the tor subprocess</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Raises :</th><td class="field-body"><p class="first last"><strong>OSError</strong> if we either fail to create the tor process or reached a timeout without success</p> </td> </tr> </tbody> </table> </dd></dl> </div> </div> <div class="bottomnav"> </div> <div class="footer"> </div> </body> </html>