Skip to content

Commit c56fcb0

Browse files
committed
---
yaml --- r: 121201 b: refs/heads/dist-snap c: 2fe9264 h: refs/heads/master i: 121199: 627f01d v: v3
1 parent 429bcb8 commit c56fcb0

File tree

3 files changed

+24
-47
lines changed

3 files changed

+24
-47
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 1813e5aa1a03b0596b8de7abd1af31edf5d6098f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 4b672a63da3083ab6d4673cdb223bc1c978ed7d2
9+
refs/heads/dist-snap: 2fe926431bb198a052a5eae92ff820a4f572fd92
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/io/process.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use c_str::CString;
5959
/// ```
6060
pub struct Process {
6161
handle: Box<RtioProcess + Send>,
62+
forget: bool,
6263

6364
/// Handle to the child's stdin, if the `stdin` field of this process's
6465
/// `ProcessConfig` was `CreatePipe`. By default, this handle is `Some`.
@@ -262,6 +263,7 @@ impl Command {
262263
});
263264
Process {
264265
handle: p,
266+
forget: false,
265267
stdin: io.next().unwrap(),
266268
stdout: io.next().unwrap(),
267269
stderr: io.next().unwrap(),
@@ -540,10 +542,23 @@ impl Process {
540542
error: stderr.recv().ok().unwrap_or(Vec::new()),
541543
})
542544
}
545+
546+
/// Forgets this process, allowing it to outlive the parent
547+
///
548+
/// This function will forcefully prevent calling `wait()` on the child
549+
/// process in the destructor, allowing the child to outlive the
550+
/// parent. Note that this operation can easily lead to leaking the
551+
/// resources of the child process, so care must be taken when
552+
/// invoking this method.
553+
pub fn forget(mut self) {
554+
self.forget = true;
555+
}
543556
}
544557

545558
impl Drop for Process {
546559
fn drop(&mut self) {
560+
if self.forget { return }
561+
547562
// Close all I/O before exiting to ensure that the child doesn't wait
548563
// forever to print some text or something similar.
549564
drop(self.stdin.take());
@@ -933,4 +948,12 @@ mod tests {
933948
rx.recv();
934949
rx.recv();
935950
})
951+
952+
iotest!(fn forget() {
953+
let p = sleeper();
954+
let id = p.id();
955+
p.forget();
956+
assert!(Process::kill(id, 0).is_ok());
957+
assert!(Process::kill(id, PleaseExitSignal).is_ok());
958+
})
936959
}

branches/dist-snap/src/libsync/comm/mod.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -120,52 +120,6 @@
120120
//! });
121121
//! rx.recv();
122122
//! ```
123-
//!
124-
//! Reading from a channel with a timeout requires to use a Timer together
125-
//! with the channel. You can use the select! macro to select either and
126-
//! handle the timeout case. This first example will break out of the loop
127-
//! after 10 seconds no matter what:
128-
//!
129-
//! ```no_run
130-
//! use std::io::timer::Timer;
131-
//!
132-
//! let (tx, rx) = channel::<int>();
133-
//! let mut timer = Timer::new().unwrap();
134-
//! let timeout = timer.oneshot(10000);
135-
//!
136-
//! loop {
137-
//! select! {
138-
//! val = rx.recv() => println!("Received {}", val),
139-
//! () = timeout.recv() => {
140-
//! println!("timed out, total time was more than 10 seconds")
141-
//! break;
142-
//! }
143-
//! }
144-
//! }
145-
//! ```
146-
//!
147-
//! This second example is more costly since it allocates a new timer every
148-
//! time a message is received, but it allows you to timeout after the channel
149-
//! has been inactive for 5 seconds:
150-
//!
151-
//! ```no_run
152-
//! use std::io::timer::Timer;
153-
//!
154-
//! let (tx, rx) = channel::<int>();
155-
//! let mut timer = Timer::new().unwrap();
156-
//!
157-
//! loop {
158-
//! let timeout = timer.oneshot(5000);
159-
//!
160-
//! select! {
161-
//! val = rx.recv() => println!("Received {}", val),
162-
//! () = timeout.recv() => {
163-
//! println!("timed out, no message received in 5 seconds")
164-
//! break;
165-
//! }
166-
//! }
167-
//! }
168-
//! ```
169123
170124
// A description of how Rust's channel implementation works
171125
//

0 commit comments

Comments
 (0)