Versions Compared

    Key

    • This line was added.
    • This line was removed.
    • Formatting was changed.
    Comment: Published by Scroll Versions from this space and version 7.5-0

    ...

    Code Block
    titlePython callback
    linenumberstrue
    languagepython
    job = {
        'prototype': 'cmdline',
        'name': 'python callback test',
        'package': {
        'cmdline': 'hostname',
        },
        'callbacks': [
            {
                'language': 'python',
                'triggers': 'done-job-self', 
                'code': '''
    try:
        import sys
        
        fh = open('c:/temp/err.txt', 'w')
        fh.close()
        
        fh = open('c:/temp/foo.txt', 'w')
        fh.write('Hello from job id %s\\n' % qb.jobid())
        fh.write('sys.version : %s\\n' % sys.version)
        fh.write('sys.version info : %s\\n' % '.'.join([str(x) for x in sys.version_info]))
        fh.write('sys.executable : %s\\n' % sys.executable)
        fh.close()
    except Exception, e:
        fh = open('c:/temp/err.txt', 'w')
        fh.write('Error from job id %s\\n' % qb.jobid())
        fh.write('%s\\n' % e)
        fh.close()
    '''
                }
            ]
        }
    print ('%(id)s: %(name)s' % qb.submit(job)[0])
    
    
    Note
    • Supervisor_language_flags must contain "python" or this callback will silently fail.
    • The qb module available inside the callback is a stripped down version of what a typical python script will consume. If you need the full python module, spawn a second script from the callback with subprocess.Popen or the like. See this example for reference.

    ...