Core¶
All applications have to have some kind of outer blcok.
Globals¶
-
core.
running
¶ This is a boolean that the application is running. It can be turned off by an application, but the
stop()
function is usually used.
-
core.
taskManager
¶ This is a reference to the
TaskManager
instance that is used to schedule some operation. There is only one task manager instance in an application.
-
core.
deferredFns
¶ This is a list of function calls to make after all of the asyncore.loop processing has completed. This is a list of (fn, args, kwargs) tuples that are appended to the list by the
deferred()
function.
-
core.
sleeptime
¶ This value is used to “sleep” the main thread for a certian amount of before continuing on to the asyncore loop. It is used to be friendly to other threads that may be starved for processing time. See
enable_sleeping()
.
Functions¶
-
core.
run
(spin=SPIN, sigterm=stop, sigusr1=print_stack)¶ Parameters: - spin – the amount of time to wait if no tasks are scheduled
- sigterm – a function to call when SIGTERM is signaled, defaults to stop
- sigusr1 – a function to call when SIGUSR1 is signaled, defaults to print_stack
This function is called by a BACpypes application after all of its initialization is complete.
The spin parameter is the maximum amount of time to wait in the sockets asyncore loop() function that waits for network activity. Setting this to a large value allows the application to consume very few system resources while there is no network activity. If the application uses threads, setting this to a large value will starve the child threads for time.
The sigterm parameter is a function to be installed as a signal handler for SIGTERM events. For historical reasons this defaults to the stop() function so that Ctrl-C in interactive applications will exit the application rather than raise a KeyboardInterrupt exception.
The sigusr1 parameter is a function to be installed as a signal handler for SIGUSR1 events. For historical reasons this defaults to the print_stack() function so if an application seems to be stuck on waiting for an event or in a long running loop the developer can trigger a “stack dump”.
The sigterm and sigusr1 parameters must be None when the run() function is called from a non-main thread.
-
core.
stop
(*args)¶ Parameters: args – optional signal handler arguments This function is called to stop a BACpypes application. It resets the
running
boolean value. This function also installed as a signal handler responding to the TERM signal so you can stop a background (deamon) process:$ kill -TERM 12345
-
core.
print_stack
(sig, frame)¶ Parameters: - sig – signal
- frame – stack trace frame
-
core.
deferred
(fn, *args, **kwargs)¶ Parameters: - fn – function to call
- args – regular arguments to pass to fn
- kwargs – keyword arguments to pass to fn
This function is called to postpone a function call until after the asyncore.loop processing has completed. See
run()
.
-
core.
enable_sleeping
([stime])¶ Parameters: stime – amount of time to sleep, defaults to one millisecond BACpypes applications are generally written as a single threaded application, the stack is not thread safe. However, applications may use threads at the application layer and above for other types of work. This function allows the main thread to sleep for some small amount of time so that it does not starve child threads of processing time.
When sleeping is enabled, and it only needs to be enabled for multithreaded applications, it will put a damper on the throughput of the application.