Child Module sw.child

Classes

class sw.child.Child(cq, wq, num, log, options)[source]

Initializes our child and then starts it. It takes our pool’s childqueue, our pool’s workqueue, our child’s number to report back statuses, our base log directory, and a collection of options.

Parameters:
  • cq – ChildQueue, this is passed from sw.pool and is used to transmit the status of the child to our pool.
  • wq – WorkQueue, also passed from sw.pool and child pops a function off of it to run (a job) when it finishes a job / starts initially.
  • num – Number of the child relevant to sw.pool‘s self.data array. This index is used to easily communicate results and relate them to the child in that array. num is also used when printing out a status message.
  • log – Base log directory which we spit logs and screenshots into.
  • options – Dict from kwargs which contains directives to pass to GhostDriver.
Returns:

Child (self)

display(t)[source]

Sends a display message to the main loop, which is then translated to the UI.

Parameters:t – The status this child will now show, a constant starting with DISP in const.py.
Returns:None
is_alive()[source]

Checks if the child’s process is still running, if it is then it returns True, otherwise False. There’s a check for if the process is None, which is set when a child terminates.

Returns:Boolean for if Child process is still active (different from if a child is processing data).
logError(e, noScreenshot=False)[source]

Log Screenshot of Error with Exception Renders a screenshot of what it sees then writes it to our log directory as error_#.png Also takes the exception we received and exports it as text

Parameters:
  • e – Unicode json-encoded string from a webdriver-thrown error.
  • noScreenshot (False) – Whether or not to take a screenshot of the error.
Returns:

String for screenshot location, if any.

logMsg(e, level=0, **kwargs)[source]

Writes to our message log if level is greater than or equal to our level (in self.log).

Parameters:
  • e – The message to be written to the log.
  • level (NOTICE) – This determines whether or not the error message will be logged according to the level set in self.level. If this error is not greater or equal to the level specified in self.level, it is not printed. If it is, the message is printed into log.txt with the level specified by the timestamp.
Kwargs:
  • locals (None): Optional locals dict to print out cleanly.
Returns:

None

restart(msg='restarting', flag=None)[source]

Restarts the child process and gets webdriver running again.

Parameters:
  • msg (“RESTARTING”) – A message to print out in parenenthesis.
  • flag (None) – A custom flag to change the display color of the child, if desired.
Returns:

None

screenshot(level=0)[source]

Saves a screenshot to error_#.png and prints a message into the log specifying the file logged to.

Parameters:level (NOTICE) – This determines whether or not the error message will be logged according to the level set in self.level. The screenshot will print anyway. If this error is not greater or equal to the level specified in self.level, it is not printed. If it is, the message is printed into log.txt with the level specified by the timestamp.
Returns:String for screenshot location
start(flag=1)[source]

Starts our child process off properly, used after a restart typically.

Parameters:flag (DISP_LOAD) – A custom flag to change the display color of the child, if desired.
Returns:None
status(type=None)[source]

Uses a multiprocess-safe variable to transmit our status upstream. These values are listed under universal status types in const.py. The status types allow better logging and, for example, prevent children that were already terminated from being terminated again (and throwing an exception).

When called with a type it will set this child’s status on both the main process and the child’s process. When called without it, it reads from the status variable.

Parameters:type (None) – The new value of our status.
Returns:If type isn’t specified, our status. If it is, it sets our type and returns None.
stop(msg='', flag=4, disp_flag=6)[source]

Stops a child process properly and sets its self.proc to None. Optionally takes a message to print out.

Parameters:
  • msg (“”) – A message to show in parenthesis on the console next to Child #: STOPPING (msg).
  • flag (FINISHED) – A custom status flag for if the child is finished, paused, stopped, or whatever is desired.
  • disp_flag (DISP_DONE) – A custom display flag for the status of the child after stopping.
Returns:

None

think()[source]

The meat of the wrapper, where the main thinking is done. Takes no arguments, just reads from self variables set in sw.Child. PhantomJS is added into the python path by run.bat, so that is already handled.

Returns:None
class sw.child.PhantomJSNoImages(*args, **kwargs)[source]

Bases: selenium.webdriver.phantomjs.service.Service

This class sits atop our PhantomJSService class included in webdriver to implemention service_args inclusion, which we pass by default –load-images=no to disable images.

Parameters:PhantomJSService – Pass this function the PhantomJSService class so that it can patch on top of it.
Returns:PhantomJsNoImages (self)

Table Of Contents

Previous topic

Child Pool Module sw.pool

Next topic

ElementCache Module sw.cache

This Page