BP is slow to start up on Raspberry Pi Zero

I’ve got an RPi0 with a PiPixel hat to run a string of APA102 LEDs. I have a script that is running different project files based on different conditions. While setting this up and playing with bp in general on this platform, I’ve observed long startup times for BP on the RPi0, typically 10-12 seconds. It looks like BP pegs at 100% CPU usage while it’s performing whatever setup it’s doing.

It doesn’t seem to be directly related to my project, as even just running ‘bp’ on it’s own also hangs for 10 seconds before returning the usage info.

pi@cubelights:~/projects $ time bp

bp - The BiblioPixel Project Runner

bp is a command-line script installed with Bibliopixel. It can run
projects and demos, configure hardware, save and load defaults, and more.
bp takes one of 20 commands:
all_pixel, all_pixel_test, clear_cache, color, demo, devices, info, list
load, monitor, pid, remove, reset, restart, run, save, set, show, shutdown, update
Some commands take arguments - often names of files.

Examples of bp commands and arguments

bp info
bp demo circle
bp run foo.json bar.json
bp foo.json bar.json # run is the default command

The commands are summarized below, and you can get more detailed help about
each one by typing:

bp --help

or

bp -h

The bp command line

bp commands have flags that control how bp runs its commands.
Examples of flags are -v, --verbose, --defaults, -d,
--simpixel. Flags either start with -, for one letter flags, or --
for multi-letter flags.
Sometimes two flags have the same meaning, like --simpixel and -s
or --verbose and -v.
Some flags take an argument, like --dim=160 or --loglevel=frame.
Other flags do not, like --verbose or -v.
A bp command line can optionally include a command, a list of arguments,
and a list of flags:

bp [] [ …] [ …]

Examples of bp command lines

bp info --help
bp run -h
bp info
bp color “indian red 4”
bp foo.json bar.json -v
bp foo.json bar.json -v --numbers=float --dump --defaults=default.json

usage: bp [-h]
{all_pixel,all_pixel_test,clear_cache,color,demo,devices,info,list,load,monitor,pid,remove,reset,restart,run,save,set,show,shutdown,update}

positional arguments:
{all_pixel,all_pixel_test,clear_cache,color,demo,devices,info,list,load,monitor,pid,remove,reset,restart,run,save,set,show,shutdown,update}
all_pixel Configure the AllPixel or similar module
all_pixel_test Test the all_pixel.
clear_cache Clear the loady git repository library cache
color Toggle between color names and color tuples
demo Run a bibliopixel demo.
devices Find serial devices and update serial device IDs
info Print information about BiblioPixel
list List all user project default files
load Load a saved project default file
monitor Monitor a control source
pid Print the process ID of the current bp instance that
is running a project, if any.
remove Remove a project default file
reset Reset sections in the project defaults
restart Send a restart signal to a BiblioPixel process running
on this machine.
run Run specified project from file or URL.
save Save the current project defaults to a file
set Set some or all sections of the project defaults
show Show all project default values
shutdown Send an interrupt signal to a BiblioPixel process
running on this machine to kill it.
update Update BiblioPixel’s dependencies
optional arguments:
-h, --help show this help message and exit
real 0m11.547s
user 0m10.567s
sys 0m0.352s

Any idea what causes the process to take so long to start up? Anything that I can change config wise to improve this startup time?

I did some more digging, and as you said, most of the time is in loading all of modules in the first place. Unfortunately, this also means it takes 10+ seconds for ‘bp restart’ to run. But that’s fine, sending a SIGHUP works perfectly and is actually easier for me.

It looks like, since bp does not hold a file handle open for the project file, I can get around this by pointing ‘bp run …’ at a symbolic link to the actual project file, then just change the link and send a SIGHUP. That should probably do what I need.

I had been considering figuring out how to do it the “old” way and writing bp directly into my script (which is also in python), but it seems from the available docs that y’all are discouraging that moving forward. It would be nice if there was a way to load bp as a module within another python program and then just feed it a project definition via a function call. If this is possible, I couldn’t figure it out.

Thanks for the assistance.

···

On Tuesday, August 21, 2018 at 4:22:52 AM UTC-5, Tom Swirly wrote:

Luckily, I think what you are more or less asking is, “How can I switch between projects really fast?” And that we have a solution for.

If bp is running in one place and you go to another terminal session and type

bp restart

it will reread your project file and restart the project without having to restart bp. (For you Unix geeks, or if you need to do this from your own script, it’s exactly the same thing as sending SIGHUP to the process that’s running bp.)

So one simple way to proceed is just to rewrite the whole project file, and send the restart message. That restarts in a few tens of milliseconds on a desktop, not even noticeable. It might well be noticeable on a P0 but still in the hundreds of milliseconds I should think.

(Rewriting the whole project is a bit blunt - though really easy to explain and do. There are more subtle solutions too. Ask me if you are interested…)


/t

https://tom.ritchford.com

https://tom.swirly.com