Enabling GPU rendering in a background script in 2.79 The structure for setting GPU rendering changed in 2.77 and after a bit of digging I came up with the following code that sets the GPU with the new structure:

bpy.context.scene.cycles.device = 'GPU'
prefs = bpy.context.user_preferences.addons['cycles'].preferences
print(prefs.compute_device_type)

for d in prefs.devices:
    print(d.name)
#2.76-
#bpy.context.user_preferences.system.compute_device_type = 'CUDA'
#bpy.context.user_preferences.system.compute_device = 'CUDA_1'
#2.77+
bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
bpy.context.user_preferences.addons['cycles'].preferences.compute_device = 'CUDA_1'
#bpy.context.user_preferences.system.compute_device = 'CUDA_MULTI_2' # Uncomment for 2 GPUs


It is picking up the GPU cards and it looks like it is setting the compute device correctly but when I look at HTOP the CPUS are being used. Is there anything I am doing incorrectly here or do I need to add additional commands?
In the end this approach worked, the server I was rendering either didn't have cycles enabled or I saved in the blend file to use CPU.