Skip to content

a wrapper for different types of calls it can be used to spawn an external process or just python code from a new thread or dedicated process with timeout support. You will get a handle that you can use to retrieve the status of the running call or to order it to stop at any point in time always using the same API regardless of the call type.

License

Notifications You must be signed in to change notification settings

blackthorne/Libcall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Libcall

a small wrapper for different types of calls, it can be used to spawn an external process or to just run python code from string onto a new thread with timeout support. This small lib adds logging and error handling in a way that can be useful for running in agents within a distributed system where you need a uniform yet flexible way to invoke different types of calls and possibly with timeouts. You will get a handle that you can use to retrieve the status of the running call or to order it to stop at any point in time always using the same API regardless of the call type.

Keep in mind this offers no Security, untrusted data should never reach any of these calls

Written for Python 2 but can easily be converted to 3

Requirements: subprocess32

Status: highly experimental

Types of calls supported:

  • subprocess (spawns external process)
  • subprocess with Shell
  • Python (threaded)

Spawn new process

    a = call.Command(['ls','-l','/'],'subprocess', logger=logger)
    b = a.start()

stdout and stderr can be reached using a.stdout or a.stderr

Spawn a Python Call

    d = call.Command('print 2+2','python-basic', logger=logger)
    d.start()

Python Call with timeout

    code = """
    import time
    while True:
        time.sleep(0.1)
    print 'end'
    """
    d = call.Command(code,'python-basic', logger=logger, timeout=2)
    d.start()

this timeout feature is not 100% reliable for this type of call (it tries to find and kill a thread internally)

Shell Call with timeout

    d = call.Command('sleep 50','shell-env', logger=logger, timeout=2)
    d.start()

About

a wrapper for different types of calls it can be used to spawn an external process or just python code from a new thread or dedicated process with timeout support. You will get a handle that you can use to retrieve the status of the running call or to order it to stop at any point in time always using the same API regardless of the call type.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages