Threaded, Directory Walking Example

Synopsis

Multithreaded example with signal handling that also demonstrates error handling.

Platform

Unix, Windows, python >=v3.5.3

Dependencies
editfrontmatter>=0.0.1
Jinja2>=2.10.1
MarkupSafe>=1.1.1
oyaml>=0.9
PyYAML>=5.1
License

MIT

Author

Karl N. Redman

homepage

EditFrontMatter Example 3

Current Release

version: 0.0.1

New in version 0.0.1: Initial Version

print_lock = <unlocked _thread.lock object>

Tread lock used for printing

STOP_ALL = False

a global thread cancel flag

exception Signal_Caught[source]

Bases: Exception

Exception to catch program signals

SignalHandler(sig, frame)[source]

Generic Signal handler.

Description:

Catches: SIGINT, SIGHUP

class Derived_EditFrontMatter(**kwargs)[source]

Bases: editfrontmatter.EditFrontMatter.EditFrontMatter

EditFrontMatter derived class for example purposes

__init__(**kwargs)[source]

Init override with some self thread handling.

Description

Instantiates the class with some thread self awareness for example puproses. Also files are read during the init process.

Variables
  • self.EXCEPTION (bool) – [default: False] Controls flow in methods if an exception is thrown during the init process.

  • STOP_ALL (bool) – [Global var] Allows for safe termination of the thread through flow control.

Throws:

EditFrontMatter_Exception

run(write_file=False, extraVars_dict={}, keys_toDelete=[], *args, **kwargs) → str[source]

A method overload to process files.

Description

Class method that performs setup for a call to editfrontmatter.EditFrontMatter.EditFrontMatter.run().

The method follows some flow control mechanisms for thread safety.

The method supresses IOError Exception with a comment loged to stderr if the exception occurs.

Parameters
Calls:

editfrontmatter.EditFrontMatter.EditFrontMatter.run()

Returns

The altered file as a string or a null string on error

canPublish_func(val) → bool[source]

simple callback for a jinja2 filter variable.

main()[source]

Main function for the program.

Description

The function set’s up the environment and artificats for processing markdown files with yaml content to be updated. The function also manages threads that perform the work.

Returns

  • 0 on success

  • 1 on error