Author Topic: Using Callbacks in Python  (Read 2736 times)


  • Full Member
  • ***
  • Posts: 15
Using Callbacks in Python
« on: June 27, 2006, 05:52:32 PM »
I'm looking at the agendaItem loop in the "C:\Program Files\pfx\qube\examples\python\" example which unblocks a childjob once the parent job has finished its frames.

    for agendaItem in agenda:
        agendaItemName = agendaItem['name']
        agendaItemCallback = {}
        agendaItemCallback['triggers'] = 'complete-work-parentJob-%s' % agendaItemName
        agendaItemCallback['language'] = 'python'
        agendaItemCallback['code'] = 'import qb'
        agendaItemCallback['code'] += '%s%s%s' % ('\nqb.workunblock(\'%s:', agendaItemName, '\' % qb.jobid())')
        agendaItemCallback['code'] += '\nqb.unblock(qb.jobid())'

I'm wondering if it's possible to execute e.g. external commands within the [ code ] key.
For example, I want to output the contents of c:\ to qubeoutput.txt on the local drive.
Adding this little snippet doesn't do much:

--- snip ---
        agendaItemCallback['code'] = 'import os'
        agendaItemCallback['code'] += '\nos.system("dir c:\\ > c:\\qubeoutput.txt" )'
--- snip ---

Does it mean that I cannot import other modules than qb or have I misunderstood tthe whole concept of the [ code] key?

« Last Edit: November 27, 2007, 09:32:48 PM by anthony »


  • Senior Software Engineer
  • Hero Member
  • *****
  • Posts: 183
Re: Callbacks (Python)
« Reply #1 on: June 28, 2006, 09:30:46 PM »
Hey Nikos,

    Actually callbacks are executed on the supervisor host.  This is because callbacks are used more for job coordination.  However we have had other clients use it to update another database automatically.  If you really need qube! to execute a command on a worker, you could chain another job to execute after the first job has finished.  I would set it up to run on the host the job was submitted from.  However you are correct in your use of the callback code, field.  If you take a look at your supervisor's C:\ you'll probably find that file.