Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install cipher.background

How to install cipher.background

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install cipher.background
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0.1
2.0.0a1Never BuiltWhy not?
1.0.1 Available View build log
Windows (64-bit)
1.0.1
2.0.0a1Never BuiltWhy not?
1.0.1 Available View build log
Mac OS X (10.5+)
1.0.1
2.0.0a1Never BuiltWhy not?
1.0.1 Available View build log
Linux (32-bit)
1.0.1
2.0.0a1Never BuiltWhy not?
1.0.1 Available View build log
Linux (64-bit)
2.0.0a1 Available View build log
1.0.1 Available View build log
2.0.0a1 Available View build log
 
License
ZPL 2.1
Depended by
Lastest release
version 2.0.0a1 on Sep 20th, 2013

A library for creating background threads that can talk to the ZODB and use local site components.

We're probably reinventing Celery.

Example

Let's assume we have a DMS with a simple publication workflow. We have two states "DRAFT" and "PUBLISH". The Problem in this example is: that the transition form "DRAFT" to "PUBLISH" takes some minutes, and we don't want the user to be waiting.

First we have create a WorkflowTransition-BackgroundThread:

System Message: ERROR/3 (<string>, line 20)

Unknown directive type "code-block".

.. code-block:: python

    class MyWorkflowTransition(BackgroundWorkerThread):
        execute = True
        description = "background worker thread (%(class_name)s) for %(site_name)s User %(user_name)s"

        def __init__(self, site_db, site_oid, site_name, user_name, daemon=True, object_oid=None):
            self.object_oid = object_oid
            super(MyWorker, self).__init__(site_db, site_oid, site_name, user_name, daemon=True)

        def scheduleNextWork(self):
            return self.execute

        def getObjectFromOID(self):
            conn = getSite()._p_jar
            return conn.get(self.object_oid)

        def doWork(self):
            sleep(15) # This is our long TASK
            self.execute = False
            document = self.getObjectFromOID()
            document.wf_status = "PUBLISHED"


We have a simple Document with an initial Workflow-State draft.

System Message: ERROR/3 (<string>, line 46)

Unknown directive type "code-block".

.. code-block:: python

   class Document(Persistent):
       wf_state = "DRAFT"


Now we have to call our WorkflowTransition.

System Message: ERROR/3 (<string>, line 54)

Unknown directive type "code-block".

.. code-block:: python

    def setWorkflow(site, document_oid, user_name):
        worker = MyWorkflowTransition(
            site_db = site._p_jar.db(),
            site_oid = site._p_oid,
            site_name = site.__name__,
            user_name = user_name,
            object_oid = document_oid,
            )
        worker.start()

When calling worker.start() the thread goes into "Background" and the user don't have to wait until the Transition is finished.

CHANGES

2.0.0a1 (2013-03-06)

  • Added support for Python 3.3.
  • Dropped support for Python 2.4 and 2.5.

1.0.2 (2012-07-31)

  • Refactor BackgroundWorkerThread to have the site returned from getSite()

1.0.1 (2012-04-05)

1.0.0 (2012-02-10)

  • Initial release as a separate package.

Subscribe to package updates

Last updated Sep 20th, 2013

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.