Need to update queue from a process

Arun Singh
  • Arun Singh

    Arun Singh - 2012-06-18

    Using process in STAX script I am running Python script(using PySTAFv3 in python script), Now I want to print message of python script to STAXMon window.

    I have created a Handle
    Have called the process to start python script (can pass handle number to python script)
    while running process I want to print the message from python script to STAXMon ..How to do this ?

    any other help on this is appreciated.


  • Arun Singh

    Arun Singh - 2012-06-19

    I am passing STADHandle to Python and using queue I am sending message to that particular Handle.
    In STAX Job I am launching the process which is calling python file and start executing, Now python is also sending message to STAX handle but now I want to get message from the queue at the time it added to the queue and want to print   till it get end Notification.  How to read message from queue and print it on run time ?

    <!- SNIP from STAX file
       <function name="main">
                    handlename = "atry"
          <message>"Welcome To ABC"</message>
    <message>"This script establish the connection"</message>
    <call function = "'staf-newhandle'">
                   'name': handlename
                   Handle_number = STAXResult   
        <message>"Handle_number is %s" %Handle_number</message>
                <message>"Handle %s Created Successfully" %handlename</message>
                <message>"Starting Python Process"</message>
    <message>"%s" %STAXJobID</message>
                <call function = "'stafprocess'">
                   'server': "local",
                   'command': "python c:\\STAF\\trial\ %s %s"  %(STAXJobID,Handle_number)
                <message>"Waiting for End Notification"</message>
                    import time
    <call function = "'staf-queue-listmsg'">
      'handle': "%s" %Handle_number
    <message>"Test Completed"</message>
                <message>"Deleting handle %s Handle_number %s " %(handlename,handlename)</message>
    <call function = "'staf-deletehandle'">
                   'handle': Handle_number
                <message>"handle %s Handle_number %s deleted " %(handlename,Handle_number)</message>


    Python File code:
    <!- SNIP
    from PySTAFv3 import *
    import sys
    JobID_fromSTAX = sys.argv;
    Handle_fromSTAX = sys.argv;

    handle = STAFHandle("MyPythonTest")

    message = 'Python script with handle %d added to queue' % (handle.handle)
    request = 'QUEUE MESSAGE %s handle %s ' % (wrapData(message), wrapData(Handle_fromSTAX))
    result = handle.submit("local", "QUEUE", request)

  • Sharon Lucas

    Sharon Lucas - 2012-06-19

    So you didn't really want to send a message to the STAX Monitor's "Messages" section as I had originally thought you did from your original description.

    You want to send a message from your Python script (executed via a <process> element in your STAX job) to a handle you created in your STAX job and receive the message.  If you explained more what you're trying to do and why you think you want to do it this way, I might be able to suggest a better way.  For example, if you simply want to know when the Python script ends, then you'll know that when the <process> element ends and you don't need to send messages between the Python script and the STAX job.

    But, if you really have a need for sending a message from the Python script to the STAX job, then look at the "Sample STAX Job 3 - Creating a STAF Handle and Using it's Queue" example in the STAX User's Guide at   It shows how you can use a STAF Handle that you create in your STAX job and use it to submit a QUEUE GET request.  Note that to be able to get a message off the STAF Handle's queue while the process is running you'll need to be running these two actions in parallel (e.g. using the <parallel> element).

  • Arun Singh

    Arun Singh - 2012-06-19

    In short, I want to do the following:

    1. will Launch a python script using process from STAX script
    2. Python script will run the certain test.
    3. I want to print step by step message of my test execution to STAX Monitor.
    4. Once my test will end, It will send PASS or FAIL message to STAX script
    5. After receiving Test notification, STAX will show the result.

  • Sharon Lucas

    Sharon Lucas - 2012-06-19

    Ok, then you don't need to use the QUEUE service or create a new STAF Handle in your STAX job.  All you have to do is pass the STAX Job ID to the Python script in your <process> element and have your Python script submit a 'SEND JOB %s MESSAGE %s' request to the STAX service on the machine where the STAX service is running specifying the STAX Job ID for the value of the JOB option to send a message to the STAX Monitor's "Message" section.  For example:

    STAX job:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!DOCTYPE stax SYSTEM "stax.dtd">
      <defaultcall function="Main"/>
      <function name="Main">
            <message log="1">'Send a message from Python script to STAX Monitor'</message>                   
            <process name="'MyPythonScript'">
              <command mode="'shell'">'python C:/test/ %s' % (STAXJobID)</command>
              <stderr mode="'stdout'"/>
            <log message="1">
              'Python Script RC=%s, STAFResult=%s, STAXResult=\n%s' % (RC, STAFResult, STAXResult)

    And here's the content of C:\test\

    from PySTAFv3 import *
    import sys

    # Get STAX Job ID passed as an argument
    staxJobID = sys.argv

    # Set to the hostname or /IP address of your STAX service machine
    # (or 'local' if the Python script is run on your STAX service machine)
    staxMachine = 'local'

    # Create a STAF handle works to use to submit STAF service requests

        handle = STAFHandle('MyPythonTest')
    except STAFException as e:
        print('Error registering with STAF, RC: %d Result: %s' % (e.rc, e.result))

    # Send a status message to the STAX Monitor

    message = 'Python script is in Step 1'
    request = 'SEND JOB %s MESSAGE %s' % (staxJobID, wrapData(message))
    result = handle.submit(staxMachine, 'STAX', request)

    if (result.rc != STAFResult.Ok):
        print('Error: RC=%s Result=%s\nSTAF %s STAX %s' % \
           (result.rc, result.result, staxMachine, request))

    print('\n*** Test successful ***')

    # Un-register the STAF handle

    result = handle.unregister()

    if (result != STAFResult.Ok):
        print('Error unregistering with STAF, RC: %d' % result)

    # Test passed - Return 0

    Then when I run this STAX job via the STAX Monitor, I see the following in the "Messages" tab of the STAX Monitor:

    20120619-13:59:59 Send a message from Python script to STAX Monitor                                                                                                                                                      
    20120619-13:59:59 Python script is in Step 1
    20120619-13:59:59 Python Script RC=0, STAFResult=None, STAXResult=

  • Arun Singh

    Arun Singh - 2012-06-20

    Thanks It's working fine ..  will ping you again if get stuck .. I am developing automation framework while STAF is base :-)


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks