timcharper / background_process Goto Github PK
View Code? Open in Web Editor NEWThe ultimate library for UNIX process control
License: MIT License
The ultimate library for UNIX process control
License: MIT License
Hi Tim,
for unknown reason "PTYBackgroundProcess.run" does not work on my Ubuntu 11.10, but "BackgroundProcess.run" will. Please find a minimal example here: http://pastebin.com/G2piFfN8
So the problem is somehow related to PTY, but I am unsure how to debug the issue. The VM is a very minimalistic Ubuntu 11.10, so are there any packages, tools or user-rights required?
To give you some broader scope, I have some trouble running cucumber (1.1.9) together with service manager (0.6.3) with Ruby 1.8.7 on Ubuntu 11.10. So I debugged the problem down to background process (1.3) not working for some reason.
It would be really awesome to get some feedback. I am happy to provide more details, logs, etc
Thanks! Jens
I have forked a project (aruba) which uses background_process. This is employed to run out of process software testing using cucumber. The problem that I have is that in some test cases the output to stdout is quite voluminous. In Ruby-1.8.7 this is not a problem. However, when I run the tests with Ruby-1.9.2 what appears to happen is a block on write is encountered because, I infer, the STDOUT buffer is not flushed and some limit is reached. I infer this from the fact that the test run which hangs is always the same one and that breaking out of the process shows STDOUT always at the same point and the last instruction is the same write to STDOUT. As I say, this is a Ruby-1.9.2 problem only.
The code block in Aruba looks like this:
def run(cmd, fail_on_error=true) cmd = detect_ruby(cmd) in_current_dir do announce_or_puts("$ cd #{Dir.pwd}") if @announce_dir announce_or_puts("$ #{cmd}") if @announce_cmd ps = BackgroundProcess.run(cmd) @last_exit_status = ps.exitstatus # waits for the process to finish @last_stdout = ps.stdout.read announce_or_puts(@last_stdout) if @announce_stdout @last_stderr = ps.stderr.read announce_or_puts(@last_stderr) if @announce_stderr end if(@last_exit_status != 0 && fail_on_error) fail("Exit status was #{@last_exit_status}. Output:\n#{combined_output}") end @last_stderr end
As you can see, replacing BackgroundProcess.run(cmd) with PTYBackgroundProcess.run(cmd) will not suffice since then the exit status and stderr are either unavailable or unusable. I tried inserting STDOUT.sync = true immediately before the call to BackgroundProcess.run but this did not change the behaviour.
Is there a technique to force the STDOUT buffer to flush that is callable either from inside Cucumber or BackgroundProcess itself.?
Any advice or insight into how to approach this problem would be deeply appreciated.
The relevant parts of the traceback
NameError: uninitialized constant PTY::ChildExited
const_missing at org/jruby/RubyModule.java:2642
wait at <....>/gems/background_process-1.3/lib/background_process/pty_background_process.rb:41
If we comment out line 46 and 47 as shown:
rescue PTY::ChildExited
true
Then everything seems to be hunky-dory (using background_service as the client component).
Some suggest solving this without having to comment out code under jruby:
unless PTY.constants.include?(:ChildExited)
module PTY
class ChildExited < RuntimeError
end
end
end
When we issue a @process.kill on ubuntu it doesn't kill it (even if we use INT). Digging in a little it looks like @process.id is the wrong pid, hence kill doesn't work.
On Ubuntu when the process is run, it runs "sh -c [my command]", which then spawns the actual command. This appears to be different from OS X where the command is executed directly (as the ruby doc implies would happen).
I assume(?) that it's the extra "sh -c" process that's causing the pid to be incorrect, since it's pointing at the "sh -c" process rather than the real command process.
We're stuck. Any help appreciated, and happy to work on it with you.
Aish
PS. The same script is working fine on OS X.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.