Code Monkey home page Code Monkey logo

tornado-subprocess's Introduction

tornado-subprocess

A module which allows you to spawn subprocesses from a tornado web application in a non-blocking fashion.

Example:

 def print_res( status, stdout, stderr, has_timed_out ) :
     if status == 0:
         print "OK:"
         print stdout
     else:
         print "ERROR:"
         print stderr
 
 t = Subprocess( print_res, timeout=30, args=[ "cat", "/etc/passwd" ] )
 t.start()
 
 #start tornado 
 t.ioloop.start()

tornado-subprocess's People

Contributors

heynemann avatar vukasin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tornado-subprocess's Issues

Finding out if a timeout happened

First of all: AMAZING PROJECT. Thank you A LOT for it.

Second, what are your thoughts on storing a flag saying if the command timed out? I was thinking something like this:

def print_res(subprocess, status, stdout, stderr) :
    if status == 0:
        print "OK:"
        print stdout
    elif subprocess.timed_out:
        print "TIMEOUT:"
        print stderr
    else:
        print "ERROR:"
        print stderr

t = Subprocess(print_res, timeout=30, args=[ "cat", "/etc/passwd" ] )
t.start()

#start tornado 
t.ioloop.start()

If you feel that's a reasonable change I can even implement it as a pull request.

Thanks again,
Bernardo Heynemann

File Descriptors or Memory Leakage

Hey man! Once again thanks for the great work!

I suspect there's some leaking of file descriptors or memory in tornado_subprocess. I couldn't repeat it so far, but our server (with both memory and CPU to spare) stats to give the error below:

OSError: [Errno 12] Cannot allocate memory

Stacktrace (most recent call last):

File "tornado/web.py", line 1021, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "tornado/web.py", line 1139, in wrapper
return method(self, _args, *_kwargs)
File "fightcode/web/handlers/fight.py", line 141, in get
vm.get_fight_results(*robot_objects)
File "fightcode/engine/v8.py", line 243, in get_fight_results
self.execute_file(vm_file.name, code_to_run_file.name, self.process_result)
File "fightcode/engine/tornado_vm.py", line 18, in execute_file
t.start()
File "tornado_subprocess/init.py", line 61, in start
self.pipe = subprocess.Popen(**self.args)
File "python2.7/subprocess.py", line 679, in init
errread, errwrite)
File "python2.7/subprocess.py", line 1143, in _execute_child
self.pid = os.fork()

Any idea on what might be happening?

Cheers,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.