qb :: backend :: pythonChildHandler :: PyCmdExecutor :: Class PyCmdExecutor
[hide private]
[frames] | no frames]

Class PyCmdExecutor

source code


The PyCmdExecutor class is used by qube loadOnce python jobtypes. It is tightly coupled to the PyCmdDispatcher class; the 2 classes are server/client relations.

A PyCmdExecutor object is instantiated by the child process and is responsible for executing commands sent from the PyCmdDispatcher over stdin. It is normally instantiated inside a child bootstrapper script.

Initialize 2 empty dicts to serve as the locals() and globals() for the exec statement used to execute the command.

Note: The definition of failure is not a boolean result of the command executed, it is the inability of the PyCmdExecutor object to actually execute the command without raising an exception.

Instance Methods [hide private]
 
__init__(self, buffer_port, promptType=None, debug=False)
Function to set up members of the class.
source code
str
__initPacker(self)
Initialize an xdrlib.Packer instance for internal use by the class member.
source code
str
__getCommandPrompt(self, promptType='>>')
Determine the string that is printed prior to echoing out to stdout the command about to be run.
source code
 
_send(self, msg)
Write a message via a PFXSimpleClient to the pyCmdDispatcher sending this instance commands.
source code
NoneType or int
execute(self, cmd)
exec a string as a python command.
source code
int
mainloop(self)
Main loop of the PyCmdExecutor.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, buffer_port, promptType=None, debug=False)
(Constructor)

source code 

Function to set up members of the class.

Parameters:
  • buffer_port (int) - The port on which a PFXSimpleServer instance is running on the localhost, used as a backChannel for communication between this instance and the pyCmdDispatcher instance sending it commands to be executed.
  • promptType (str) - Used to determine the string used as a prompt that precedes the command when echoing the command to stdout.
Overrides: object.__init__

__initPacker(self)

source code 

Initialize an xdrlib.Packer instance for internal use by the class member.

The packer instance is accessed via the self.packer attribute.

Returns: str
the integer 0 packed into 4 bytes. This is the data most commonly sent back to the PyCmdDispatcher parent, so it's packed once and re-used.

__getCommandPrompt(self, promptType='>>')

source code 

Determine the string that is printed prior to echoing out to stdout the command about to be run.

Returns: str
The string to be used as a command prompt.

_send(self, msg)

source code 

Write a message via a PFXSimpleClient to the pyCmdDispatcher sending this instance commands.

Successful execution results in the integer 0, packed into 4 bytes, being sent with no other message behind it. Failure, defined as any command which raises an uncaught exception, results in the traceback from the exception being sent, preceded by the packed messageLength.

Parameters:
  • msg (string) - The message to be sent, prepended with the payload size packed into 4 bytes.

execute(self, cmd)

source code 

exec a string as a python command.

Most exceptions raised by the failure of exec will be caught and handled by PyCmdExecutor.mainloop. The only exception caught here will be SystemExit.

Parameters:
  • cmd (string) - The command to be run.
Returns: NoneType or int
None on success or the exitcode passed to sys.exit()

mainloop(self)

source code 

Main loop of the PyCmdExecutor. Responsible solely for reading commands to execute over stdin.

Successful execution results in a zero integer being passed back to the the PyCmdDispatcher via the PFXClient instance (the backChannel). Unsuccessful commands result in an error message of some sort being returned via the backChannel.

The traceback generated by the failure to execute the command is what gets written to the backChannel.

Returns: int
The exit code of the child process