This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description
Author : Yves-Gwenael Bourhis

==================================================
Wrap a shell comand into a python threaded object.
==================================================

Usage:
======

You want to launch the following bash commands in a thread::

[user@localhost ~]$ ls -l | grep pdf | wc -l
5

here is how you can do it::

>>> Ls = WrapCommand( 'ls -l')
>>> GrepPdf = WrapCommand( 'grep pdf')
>>> Wc = WrapCommand( 'wc -l')
>>> Wc.stdin = GrepPdf
>>> GrepPdf.stdin = Ls
>>> Wc.start( )
>>> #Do stuff
...
>>> Wc.join()
>>> Wc.results
('5\n', '')

the 'results' property is a tuple (stdoutdata, stderrdata)

You can also do it this way::

>>> Ls = WrapCommand( 'ls -l | grep pdf | wc -l', shell=True)
>>> Ls.start()
>>> #Do stuff
>>> Ls.join()
>>> Ls.results[0]
'5\n'

You would need to specify 'shell=True' when the command
you wish to execute is actually built into the shell.
i.e.: on Windows if you use built in commands such as 'dir' or 'copy':
http://docs.python.org/library/subprocess.html#subprocess.Popen

The purpose of doing it in a thread is when the above commands may
take a few hours, and that you want to perform other tasks in the
meanwhile.
You can check the process is still running with::

>>> Wc.is_alive( )
False

'True' would be returned if still running.
To terminate it prematurely (i.e. it deadlocked) you have the
'terminate()', 'kill()' or 'send_signal(signal) methods which are
self speaking.
When you want to wait for the thread to end, use the 'join()' method:
http://docs.python.org/library/threading.html#threading.Thread.join


You want to launch the following bash commands without threading::

[user@localhost ~]$ ls -l | grep pdf | wc -l
5

here is how you can do it::

>>> Ls = WrapCommand( 'ls -l')
>>> GrepPdf = WrapCommand( 'grep pdf')
>>> Wc = WrapCommand( 'wc -l')
>>> Wc(GrepPdf(Ls))
'5\n'

Avoid doing this for processes where a large amount of data is piped
between each command.

instead, do it this way::

>>> Ls = WrapCommand( 'ls -l | grep pdf | wc -l', shell=True)
>>> Ls()
'5\n'

Prefer the threaded method instead if this may take a long time and
that you want to perform other tasks in the meanwhile.


You can specify another shell for running commands::

>>> Ls = WrapCommand( 'ls', shell=True, executable='C:/windows/System32/WindowsPowerShell/v1.0/powershell.exe')
>>> print Ls()

Directory : C:\Users\Yves\python_tests

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 27/01/2011 00:14 7006 commandwrapper.py
-a--- 27/01/2011 00:15 7048 commandwrapper.pyc


You can also use Context Management (with_item):
http://docs.python.org/reference/compound_stmts.html#grammar-token-with_item

example::

>>> with WrapCommand( 'ls -l') as Ls:
... with WrapCommand( 'grep pdf') as GrepPdf:
... with WrapCommand( 'wc -l') as Wc:
... Wc.stdin = GrepPdf
... GrepPdf.stdin = Ls
... Wc.start( )
... #Do stuff
... Wc.join()
...
>>> Wc.results
('5\n', '')

You may also simply want to have a subprocess objet::

>>> ls = WrapCommand( 'ls -l')
>>> lscmd = ls.makeCmd()
>>>

the returned object (`lscmd` in the example above) is a standard subprocess.Popen object


WrapOnceCommand is the same as WrapCommand, but the cmd attribute
which is a subprocess.Popen object will be created once and for all
Therefore the run methode (or the object) can only be called once.
The goal it to launch a command in a thread, and to have this
command easily start/stopped from elsewhere.


===============
Release Notes :
===============

Release 0.1:
============

First Version

Release 0.4:
============

Removed the destructor (__del__ method) because of:

+ The Warning here:
http://docs.python.org/reference/datamodel.html#object.__del__

+ Destroyed objects where not automaticaly removed by the
garbage collector as described here:
http://docs.python.org/library/gc.html#gc.garbage
Which could cause memory usage increase.

Release 0.7:
============

Changed author's contact info.
Release History

Release History

0.7

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
commandwrapper-0.7.zip (5.5 kB) Copy SHA256 Checksum SHA256 Source Feb 17, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting