iprocess 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/README.md +22 -13
- data/iprocess.gemspec +4 -3
- data/lib/iprocess/version.rb +1 -1
- data/lib/iprocess.rb +4 -4
- metadata +29 -14
- data/lib/iprocess/channel.rb +0 -72
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -11,18 +11,20 @@ __OVERVIEW__
|
|
11
11
|
|
12
12
|
__DESCRIPTION__
|
13
13
|
|
14
|
-
Provides a number of
|
15
|
-
interprocess
|
16
|
-
|
17
|
-
|
14
|
+
Provides a number of abstractions on top of spawning subprocesses and
|
15
|
+
interprocess communication. The API is simple, easy to use & supports
|
16
|
+
both synchronous and asynchronous(non-blocking) dispatch of subprocesses.
|
17
|
+
It also supports implicit interprocess communication that can be easily
|
18
|
+
configured to use the serializer of your choice(default is the
|
19
|
+
[Marshal](http://rdoc.info/stdlib/core/Marshal) module) if needs be.
|
18
20
|
|
19
21
|
__EXAMPLES__
|
20
22
|
|
21
23
|
__1.__
|
22
24
|
|
23
|
-
|
24
|
-
executed in a subprocess, is returned to the parent process as long
|
25
|
-
be serialized by Marshal(or the serializer of your choice, this is
|
25
|
+
In this example three subprocesses are spawned. The return value of the block,
|
26
|
+
even though executed in a subprocess, is returned to the parent process as long
|
27
|
+
as it may be serialized by Marshal(or the serializer of your choice, this is
|
26
28
|
configurable):
|
27
29
|
|
28
30
|
messages = IProcess.spawn(3) { {msg: "hello"} }
|
@@ -91,19 +93,26 @@ __PLATFORM SUPPORT__
|
|
91
93
|
|
92
94
|
_supported_
|
93
95
|
|
94
|
-
*
|
95
|
-
* CRuby (1.9)
|
96
|
+
* CRuby (1.9+)
|
96
97
|
|
97
98
|
_unsupported_
|
98
99
|
|
99
100
|
* CRuby 1.8
|
100
101
|
* MacRuby
|
101
102
|
* JRuby
|
102
|
-
|
103
|
-
__LICENSE__
|
104
|
-
|
105
|
-
MIT. See LICENSE.txt.
|
103
|
+
* Rubinius (support for Rubinius will come sometime in the future).
|
106
104
|
|
107
105
|
__INSTALL__
|
108
106
|
|
109
107
|
$ gem install iprocess
|
108
|
+
|
109
|
+
__SEE ALSO__
|
110
|
+
|
111
|
+
- [XPool](https://github.com/robgleeson/xpool)
|
112
|
+
XPool is a UNIX process pool that was born inside IProcess but later extracted
|
113
|
+
into its own project. It might be interesting to you if you're interested in
|
114
|
+
concurrency and/or interprocess communication.
|
115
|
+
|
116
|
+
__LICENSE__
|
117
|
+
|
118
|
+
MIT. See LICENSE.txt.
|
data/iprocess.gemspec
CHANGED
@@ -17,10 +17,11 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_path = 'lib'
|
18
18
|
s.rubyforge_project = '[none]'
|
19
19
|
s.required_rubygems_version = '>= 1.3.6'
|
20
|
-
s.required_ruby_version = '
|
20
|
+
s.required_ruby_version = '>= 1.9.2'
|
21
21
|
|
22
|
+
s.add_runtime_dependency 'ichannel', '~> 1.0.0'
|
22
23
|
s.add_development_dependency 'yard' , '~> 0.7'
|
24
|
+
s.add_development_dependency 'minitest', '~> 2.6'
|
25
|
+
s.add_development_dependency 'rake', '~> 0.9.2'
|
23
26
|
s.add_development_dependency 'kramdown'
|
24
|
-
s.add_development_dependency 'minitest' , '~> 2.6'
|
25
|
-
s.add_development_dependency 'rake' , '~> 0.9.2'
|
26
27
|
end
|
data/lib/iprocess/version.rb
CHANGED
data/lib/iprocess.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class IProcess
|
2
|
+
require 'ichannel'
|
2
3
|
require_relative 'iprocess/version'
|
3
|
-
require_relative 'iprocess/channel'
|
4
4
|
#
|
5
5
|
# @return [#load,#dump]
|
6
6
|
# Returns the serializer used by IProcess.
|
@@ -106,8 +106,8 @@ class IProcess
|
|
106
106
|
# The process ID of the spawned subprocess.
|
107
107
|
#
|
108
108
|
def execute
|
109
|
-
@channel = IProcess
|
110
|
-
@pid = fork { @channel.
|
109
|
+
@channel = IChannel.new IProcess.serializer
|
110
|
+
@pid = fork { @channel.put(@worker.call) }
|
111
111
|
end
|
112
112
|
|
113
113
|
#
|
@@ -116,6 +116,6 @@ class IProcess
|
|
116
116
|
#
|
117
117
|
def result
|
118
118
|
Process.wait(@pid)
|
119
|
-
@channel.
|
119
|
+
@channel.get
|
120
120
|
end
|
121
121
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,40 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: ichannel
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.0.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: yard
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
37
|
+
version: '0.7'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
45
|
+
version: '0.7'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: minitest
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.9.2
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: kramdown
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: IProcess makes InterProcess Communication(IPC) easy.
|
79
95
|
email: rob@flowof.info
|
80
96
|
executables: []
|
@@ -92,7 +108,6 @@ files:
|
|
92
108
|
- Rakefile
|
93
109
|
- iprocess.gemspec
|
94
110
|
- lib/iprocess.rb
|
95
|
-
- lib/iprocess/channel.rb
|
96
111
|
- lib/iprocess/version.rb
|
97
112
|
- test/setup.rb
|
98
113
|
- test/test_IProcess_class.rb
|
@@ -105,9 +120,9 @@ require_paths:
|
|
105
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
121
|
none: false
|
107
122
|
requirements:
|
108
|
-
- -
|
123
|
+
- - ! '>='
|
109
124
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.9.
|
125
|
+
version: 1.9.2
|
111
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
127
|
none: false
|
113
128
|
requirements:
|
data/lib/iprocess/channel.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'socket'
|
2
|
-
class IProcess::Channel
|
3
|
-
#
|
4
|
-
# @param [#dump,#load}] serializer
|
5
|
-
# Any object that implements dump, & load.
|
6
|
-
# Defaults to {IProcess.serializer}.
|
7
|
-
#
|
8
|
-
# @yieldparam [IProcess::Channel] _self
|
9
|
-
# Yields self.
|
10
|
-
#
|
11
|
-
def initialize(serializer = IProcess.serializer)
|
12
|
-
@reader, @writer = UNIXSocket.pair :DGRAM
|
13
|
-
@serializer = serializer
|
14
|
-
if block_given?
|
15
|
-
yield self
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
# Close the channel.
|
21
|
-
#
|
22
|
-
# @return [void]
|
23
|
-
#
|
24
|
-
def close
|
25
|
-
[@reader.close,@writer.close]
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# @return [Boolean]
|
30
|
-
# Returns true if the channel is closed.
|
31
|
-
#
|
32
|
-
def closed?
|
33
|
-
@reader.closed? && @writer.closed?
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# @return [Boolean]
|
38
|
-
# Returns true if the channel is open.
|
39
|
-
#
|
40
|
-
def open?
|
41
|
-
!closed?
|
42
|
-
end
|
43
|
-
|
44
|
-
#
|
45
|
-
# Add an object to the channel.
|
46
|
-
#
|
47
|
-
# @param [Object] object
|
48
|
-
# An object to add to the channel.
|
49
|
-
#
|
50
|
-
def write object
|
51
|
-
_, writable, _ = IO.select [], [@writer], [], 0.1
|
52
|
-
if writable
|
53
|
-
@writer.send @serializer.dump(object), 0
|
54
|
-
end
|
55
|
-
end
|
56
|
-
alias_method :put, :write
|
57
|
-
|
58
|
-
#
|
59
|
-
# Receive a object from the channel.
|
60
|
-
#
|
61
|
-
# @return [Object]
|
62
|
-
# The object added to the channel.
|
63
|
-
#
|
64
|
-
def recv
|
65
|
-
readable, _ = IO.select [@reader], [], [], 0.1
|
66
|
-
if readable
|
67
|
-
msg, _ = @reader.recvmsg
|
68
|
-
@serializer.load msg
|
69
|
-
end
|
70
|
-
end
|
71
|
-
alias_method :get, :recv
|
72
|
-
end
|