1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
"DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
<title>twisted.internet.process.Process</title>
7
<link rel="stylesheet" href="epydoc.css" type="text/css"></link>
9
<body bgcolor="white" text="black" link="blue" vlink="#204080"
12
<!-- =========== START OF NAVBAR =========== -->
13
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
15
<th class="navbar"> <a class="navbar" href="twisted.html">Home</a> </th>
16
<th class="navbar"> <a class="navbar" href="trees.html">Trees</a> </th>
17
<th class="navbar"> <a class="navbar" href="indices.html">Index</a> </th>
18
<th class="navbar"> <a class="navbar" href="help.html">Help</a> </th>
19
<th class="navbar" align="right" width="100%">
20
<table border="0" cellpadding="0" cellspacing="0">
21
<tr><th class="navbar" align="center">
23
<a class="navbar" target="_top" href="http://twistedmatrix.com/">Twisted 1.3.0rc1</a>
24
</p></th></tr></table>
28
<table width="100%" cellpadding="0" cellspacing="0">
31
<font size="-1"><b class="breadcrumbs">
32
<a href="twisted.html">Package twisted</a> ::
33
<a href="twisted.internet.html">Package internet</a> ::
34
<a href="twisted.internet.process.html">Module process</a> ::
38
<td><table cellpadding="0" cellspacing="0">
39
<tr><td align="right"><font size="-2">[<a href="frames.html"target="_top">frames</a> | <a href="twisted.internet.process.Process.html" target="_top">no frames</a>]</font></td></tr>
43
<!-- =========== START OF CLASS DESCRIPTION =========== -->
44
<h2 class="class">Class Process</h2>
46
<pre class="base-tree">
47
<a href="twisted.persisted.styles.Ephemeral.html"><code>Ephemeral</code></a> --+
54
<p>An operating-system Process.</p>
55
<p>This represents an operating-system process with arbitrary
56
input/output pipes connected to it. Those pipes may represent standard
57
input, standard output, and standard error, or any other file
59
On UNIX, this is implemented using fork(), exec(), pipe() and fcntl().
60
These calls may not exist elsewhere so this code is not cross-platform.
61
(also, windows can only select on sockets...)
65
<!-- =========== START OF METHOD SUMMARY =========== -->
66
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
67
<tr bgcolor="#70b0f0" class="summary">
68
<th colspan="2">Method Summary</th></tr>
69
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
70
<td><code><span class="summary-sig"><a href="twisted.internet.process.Process.html#__init__" class="summary-sig-name"><code>__init__</code></a>(<span class=summary-sig-arg>self</span>,
71
<span class=summary-sig-arg>reactor</span>,
72
<span class=summary-sig-arg>command</span>,
73
<span class=summary-sig-arg>args</span>,
74
<span class=summary-sig-arg>environment</span>,
75
<span class=summary-sig-arg>path</span>,
76
<span class=summary-sig-arg>proto</span>,
77
<span class=summary-sig-arg>uid</span>,
78
<span class=summary-sig-arg>gid</span>,
79
<span class=summary-sig-arg>childFDs</span>)</span></code>
81
Spawn an operating-system process.</td></tr>
82
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
83
<td><code><a name="_execChild"></a><span class="summary-sig"><span class="summary-sig-name">_execChild</span>(<span class=summary-sig-arg>self</span>,
84
<span class=summary-sig-arg>path</span>,
85
<span class=summary-sig-arg>settingUID</span>,
86
<span class=summary-sig-arg>uid</span>,
87
<span class=summary-sig-arg>gid</span>,
88
<span class=summary-sig-arg>command</span>,
89
<span class=summary-sig-arg>args</span>,
90
<span class=summary-sig-arg>environment</span>)</span></code>
92
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
93
<td><code><span class="summary-sig"><a href="twisted.internet.process.Process.html#_setupChild" class="summary-sig-name"><code>_setupChild</code></a>(<span class=summary-sig-arg>self</span>,
94
<span class=summary-sig-arg>fdmap</span>)</span></code>
96
fdmap[childFD] = parentFD
98
The child wants to end up with 'childFD' attached to what used to be
99
the parent's parentFD.</td></tr>
100
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
101
<td><code><a name="childConnectionLost"></a><span class="summary-sig"><span class="summary-sig-name">childConnectionLost</span>(<span class=summary-sig-arg>self</span>,
102
<span class=summary-sig-arg>childFD</span>)</span></code>
104
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
105
<td><code><a name="closeChildFD"></a><span class="summary-sig"><span class="summary-sig-name">closeChildFD</span>(<span class=summary-sig-arg>self</span>,
106
<span class=summary-sig-arg>childFD</span>)</span></code>
108
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
109
<td><code><a name="closeStderr"></a><span class="summary-sig"><span class="summary-sig-name">closeStderr</span>(<span class=summary-sig-arg>self</span>)</span></code>
111
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
112
<td><code><span class="summary-sig"><a href="twisted.internet.process.Process.html#closeStdin" class="summary-sig-name"><code>closeStdin</code></a>(<span class=summary-sig-arg>self</span>)</span></code>
114
Call this to close standard input on this process.</td></tr>
115
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
116
<td><code><a name="closeStdout"></a><span class="summary-sig"><span class="summary-sig-name">closeStdout</span>(<span class=summary-sig-arg>self</span>)</span></code>
118
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
119
<td><code><a name="loseConnection"></a><span class="summary-sig"><span class="summary-sig-name">loseConnection</span>(<span class=summary-sig-arg>self</span>)</span></code>
121
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
122
<td><code><a name="maybeCallProcessEnded"></a><span class="summary-sig"><span class="summary-sig-name">maybeCallProcessEnded</span>(<span class=summary-sig-arg>self</span>)</span></code>
124
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
125
<td><code><a name="pauseProducing"></a><span class="summary-sig"><span class="summary-sig-name">pauseProducing</span>(<span class=summary-sig-arg>self</span>)</span></code>
127
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
128
<td><code><a name="processEnded"></a><span class="summary-sig"><span class="summary-sig-name">processEnded</span>(<span class=summary-sig-arg>self</span>,
129
<span class=summary-sig-arg>status</span>)</span></code>
131
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
132
<td><code><span class="summary-sig"><a href="twisted.internet.process.Process.html#reapProcess" class="summary-sig-name"><code>reapProcess</code></a>(<span class=summary-sig-arg>self</span>)</span></code>
134
Try to reap a process (without blocking) via waitpid.</td></tr>
135
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
136
<td><code><a name="resumeProducing"></a><span class="summary-sig"><span class="summary-sig-name">resumeProducing</span>(<span class=summary-sig-arg>self</span>)</span></code>
138
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
139
<td><code><a name="signalProcess"></a><span class="summary-sig"><span class="summary-sig-name">signalProcess</span>(<span class=summary-sig-arg>self</span>,
140
<span class=summary-sig-arg>signalID</span>)</span></code>
142
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
143
<td><code><span class="summary-sig"><a href="twisted.internet.process.Process.html#write" class="summary-sig-name"><code>write</code></a>(<span class=summary-sig-arg>self</span>,
144
<span class=summary-sig-arg>data</span>)</span></code>
146
Call this to write to standard input on this process.</td></tr>
147
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
148
<td><code><a name="writeToChild"></a><span class="summary-sig"><span class="summary-sig-name">writeToChild</span>(<span class=summary-sig-arg>self</span>,
149
<span class=summary-sig-arg>childFD</span>,
150
<span class=summary-sig-arg>data</span>)</span></code>
152
<tr bgcolor="#e8f0f8" class="group">
153
<th colspan="2"> Inherited from Ephemeral</th></tr>
154
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
155
<td><code><span class="summary-sig"><a href="twisted.persisted.styles.Ephemeral.html#__getstate__" class="summary-sig-name"><code>__getstate__</code></a>(<span class=summary-sig-arg>self</span>)</span></code>
157
<tr><td align="right" valign="top" width="15%"><font size="-1"> </font></td>
158
<td><code><span class="summary-sig"><a href="twisted.persisted.styles.Ephemeral.html#__setstate__" class="summary-sig-name"><code>__setstate__</code></a>(<span class=summary-sig-arg>self</span>,
159
<span class=summary-sig-arg>state</span>)</span></code>
164
<!-- =========== START OF CLASS VARIABLE SUMMARY =========== -->
165
<table class="summary" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
166
<tr bgcolor="#70b0f0" class="summary">
167
<th colspan="2">Class Variable Summary</th></tr>
168
<tr><td align="right" valign="top" width="15%"><font size="-1"><code>int</code></font></td>
169
<td><b><a href="twisted.internet.process.Process.html#debug"><code>debug</code></a></b> = <span title="0">0 </span></td></tr>
170
<tr><td align="right" valign="top" width="15%"><font size="-1"><code>int</code></font></td>
171
<td><b><a href="twisted.internet.process.Process.html#debug_child"><code>debug_child</code></a></b> = <span title="0">0 </span></td></tr>
175
<!-- =========== START OF METHOD DETAILS =========== -->
176
<table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
177
<tr bgcolor="#70b0f0" class="details">
178
<th colspan="2">Method Details</th></tr>
181
<a name="__init__"></a>
182
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
183
<h3><span class="sig"><span class="sig-name">__init__</span>(<span class=sig-arg>self</span>,
184
<span class=sig-arg>reactor</span>,
185
<span class=sig-arg>command</span>,
186
<span class=sig-arg>args</span>,
187
<span class=sig-arg>environment</span>,
188
<span class=sig-arg>path</span>,
189
<span class=sig-arg>proto</span>,
190
<span class=sig-arg>uid</span>=<span class=sig-default>None</span>,
191
<span class=sig-arg>gid</span>=<span class=sig-default>None</span>,
192
<span class=sig-arg>childFDs</span>=<span class=sig-default>None</span>)</span>
193
<br /><i>(Constructor)</i>
195
<pre class="literalblock">
196
Spawn an operating-system process.
198
This is where the hard work of disconnecting all currently open
199
files / forking / executing the new process happens. (This is
200
executed automatically when a Process is instantiated.)
202
This will also run the subprocess as a given user ID and group ID, if
203
specified. (Implementation Note: this doesn't support all the arcane
204
nuances of setXXuid on UNIX: it will assume that either your effective
207
@param childFDs: a dictionary mapping
208
fd_in_child -> current_fd_in_parent/'r'/'w'
210
If the value is a number, it specifies one of the parent's fds
211
that will be remapped to the child's fd. This is useful for
212
things like inetd and shell-like file redirection.
214
If it is the string 'r', a pipe will be created and attached to
215
the child at that fd number, and the parent will be able to
216
read from the pipe. This is useful for the child's stdout and
219
If it is the string 'w', a pipe will be created and attached,
220
and the parent will be able to write into that pipe. This is
221
useful for the child's stdin.
223
If childFDs is not passed, the default behaviour is to use a
224
mapping that opens the usual stdin/stdout/stderr pipes.
230
<a name="_setupChild"></a>
231
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
232
<h3><span class="sig"><span class="sig-name">_setupChild</span>(<span class=sig-arg>self</span>,
233
<span class=sig-arg>fdmap</span>)</span>
235
<pre class="literalblock">
236
fdmap[childFD] = parentFD
238
The child wants to end up with 'childFD' attached to what used to be
239
the parent's parentFD. As an example, a bash command run like
240
'command 2>&1' would correspond to an fdmap of {0:0, 1:1, 2:1}.
241
'command >foo.txt' would be {0:0, 1:os.open('foo.txt'), 2:2}.
243
Step 1: close all file descriptors that aren't values of fdmap.
244
This means 0 .. maxfds.
246
Step 2: for each childFD:
247
if fdmap[childFD] == childFD, the descriptor is already in place.
248
Make sure the CLOEXEC flag is not set, then delete the entry from
251
if childFD is in fdmap.values(), then the target descriptor is
252
busy. Use os.dup() to move it elsewhere, update all fdmap[childFD]
253
items that point to it, then close the original. Then fall through
256
now fdmap[childFD] is not in fdmap.values(), and is free. Use
257
os.dup2() to move it to the right place, then close the original.
263
<a name="closeStdin"></a>
264
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
265
<h3><span class="sig"><span class="sig-name">closeStdin</span>(<span class=sig-arg>self</span>)</span>
267
Call this to close standard input on this process.
272
<a name="reapProcess"></a>
273
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
274
<h3><span class="sig"><span class="sig-name">reapProcess</span>(<span class=sig-arg>self</span>)</span>
276
<p>Try to reap a process (without blocking) via waitpid.</p>
277
<p>This is called when sigchild is caught or a Process object loses its
278
"connection" (stdout is closed) This ought to result in
279
reaping all zombie processes, since it will be called twice as often as
281
(Unfortunately, this is a slightly experimental approach, since UNIX
282
has no way to be really sure that your process is going to go away w/o
283
blocking. I don't want to block.)
289
<table width="100%" class="func-details" bgcolor="#e0e0e0"><tr><td>
290
<h3><span class="sig"><span class="sig-name">write</span>(<span class=sig-arg>self</span>,
291
<span class=sig-arg>data</span>)</span>
293
Call this to write to standard input on this process.
300
<!-- =========== START OF CLASS VARIABLE DETAILS =========== -->
301
<table class="details" border="1" cellpadding="3" cellspacing="0" width="100%" bgcolor="white">
302
<tr bgcolor="#70b0f0" class="details">
303
<th colspan="2">Class Variable Details</th></tr>
305
<table width="100%" class="var-details" bgcolor="#e0e0e0"><tr><td>
312
<dt><b>Type:</b></dt>
317
<span title="0"> <dt><b>Value:</b></dt>
319
<pre class="variable">
320
0 </pre>
321
</td></tr></table></dd>
324
</dl></td></tr></table>
325
<table width="100%" class="var-details" bgcolor="#e0e0e0"><tr><td>
326
<a name="debug_child"></a>
332
<dt><b>Type:</b></dt>
337
<span title="0"> <dt><b>Value:</b></dt>
339
<pre class="variable">
340
0 </pre>
341
</td></tr></table></dd>
344
</dl></td></tr></table>
348
<!-- =========== START OF NAVBAR =========== -->
349
<table class="navbar" border="0" width="100%" cellpadding="0" bgcolor="#a0c0ff" cellspacing="0">
351
<th class="navbar"> <a class="navbar" href="twisted.html">Home</a> </th>
352
<th class="navbar"> <a class="navbar" href="trees.html">Trees</a> </th>
353
<th class="navbar"> <a class="navbar" href="indices.html">Index</a> </th>
354
<th class="navbar"> <a class="navbar" href="help.html">Help</a> </th>
355
<th class="navbar" align="right" width="100%">
356
<table border="0" cellpadding="0" cellspacing="0">
357
<tr><th class="navbar" align="center">
359
<a class="navbar" target="_top" href="http://twistedmatrix.com/">Twisted 1.3.0rc1</a>
360
</p></th></tr></table>
365
<table border="0" cellpadding="0" cellspacing="0" width="100%">
367
<td align="left"><font size="-2">Generated by Epydoc 2.0 on Sat May 15 20:08:06 2004</font></td>
368
<td align="right"><a href="http://epydoc.sourceforge.net"
369
><font size="-2">http://epydoc.sf.net</font></a></td>