HWRF  trunk@4391
setup.py
1 """!Contains setup(), which initializes the produtil package.
2 
3 This module contains the setup() function that should be called once
4 by every Python process started, immediately after Python starts."""
5 
6 ##@var __all__
7 # Lists symbols exported by "from produtil.setup import *"
8 __all__=['setup']
9 
10 import logging, threading
13 
14 def setup(ignore_hup=False,dbnalert_logger=None,jobname=None,cluster=None,
15  send_dbn=None,thread_logger=False,thread_stack=2**24,**kwargs):
16  """!Initializes the produtil package. Calls the module
17  initialization functions for all other modules in the produtil
18  package.
19 
20  At present, it:
21 
22  1. Installs signal handlers that will cleanly abort the process.
23  2. Sets up logging to the jlogfile, if $jlogfile is in the environment.
24  3. Sets up logging to stdout and stderr.
25  4. Sets up the produtil.dbnalert module so DBNAlert objects will
26  function properly
27  5. Sets the produtil.cluster's idea of what cluster it is on. If no
28  cluster is specified, the produtil.cluster is instructed to guess.
29 
30  This is a wrapper around the produtil.sigsafety, and produtil.log,
31  and other module initializers. Note that one could call each
32  module's initialization functions directly instead. However, one
33  would have to keep up with changes to the produtil package during
34  upgrades in order to do that.
35 
36  @param ignore_hup if True, this program will ignore SIGHUP. Use
37  this for UNIX daemon processes. Turned off (False) by default,
38  causing SIGHUP to be a terminal signal.
39  @param dbnalert_logger sent to dbnalert.init_module's logger argument
40  to initialize the logging domain for informational messages
41  about dbn alerts
42  @param jobname dbn_alert job string
43  @param cluster if specified and not None, sent to produtil.cluster's
44  set_cluster. Otherwise, produtil.cluster.where() is called to
45  guess the cluster, or set suitable defaults.
46  @param send_dbn should dbn alerts be sent?
47  @param thread_logger if True, log messages will include thread name.
48  @param thread_stack passed to threading.stack_size(); the stack size in
49  bytes for new threads. The default is 2**24, which is 16 MB.
50  See the threading module for details. Set to None to disable
51  changing of the threading stack size.
52  @param kwargs all other keyword args sent to produtil.log.configureLogging()"""
53 
54  # Set the threading stack size first so any threads launched by
55  # Python will have reasonable stack sizes. This is intended to
56  # prevent problems seen by some users where Python will be unable
57  # to spawn any threads:
58  if thread_stack is not None:
59  threading.stack_size(thread_stack)
60 
61  # Set the default jobname. This is usually used for manually-run
62  # scripts to ensure they have a "jobname" in the logging system:
63  if jobname is not None:
65 
66  # Configure logging next so that the install_handlers will be able
67  # to log.
68  produtil.log.configureLogging(thread_logger=thread_logger,**kwargs)
69  # Install signal handlers, and let the caller configure SIGHUP settings:
70  produtil.sigsafety.install_handlers(ignore_hup=ignore_hup)
71  # Set up dbnalert:
72  produtil.dbnalert.init_module(logger=dbnalert_logger,jobname=jobname,
73  send_dbn=send_dbn)
74 
75  # Set up cluster:
76  if cluster is not None:
78  else:
79  produtil.cluster.where() # guess cluster
def install_handlers
Installs signal handlers that will raise exceptions.
Definition: sigsafety.py:153
Sets up signal handlers to ensure a clean exit.
Definition: sigsafety.py:1
def where()
Guesses what cluster the program is running on, and if it cannot, returns a cluster named "noname" wi...
Definition: cluster.py:71
def setup(ignore_hup=False, dbnalert_logger=None, jobname=None, cluster=None, send_dbn=None, thread_logger=False, thread_stack=2 **24, kwargs)
Initializes the produtil package.
Definition: setup.py:15
Provides information about the cluster on which this job is running.
Definition: cluster.py:1
This module runs the NCO dbn_alert program, or logs dbn_alert messages if run with dbn alerts disable...
Definition: dbnalert.py:1
def set_default_name(default_name)
Set default for all job names.
Definition: batchsystem.py:39
def configureLogging
Configures log output to stderr, stdout and the jlogfile.
Definition: log.py:310
Configures logging.
Definition: log.py:1
def set_cluster(there)
Sets the current cluster (module-level "here" variable) to the given value.
Definition: cluster.py:63
Provides information about the batch system.
Definition: batchsystem.py:1
def init_module
Call to initialize this module.
Definition: dbnalert.py:193