How to Override Poll for Clear_Parent in Background mode I keep running into a poll context error for when trying to parent_clear-
  File &quot;c:\Users\Willard\Desktop\blender\2.82\scripts\modules\bpy\ops.py&quot;, line 199, in __call__
    ret = op_call(self.idname_py(), C_dict, kw, C_exec, C_undo)
RuntimeError: Operator bpy.ops.object.parent_clear.poll() failed, context is incorrect

My script works fine and avoids poll errors when running blender with the interface.
for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        for region in area.regions:
            if region.type == 'WINDOW':
                override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object}

for s in bpy.context.scene.objects:
    if s.type == 'MESH' and s.parent_type == 'OBJECT': 
         s.select_set(True)
         bpy.ops.object.parent_clear(override, type='CLEAR_KEEP_TRANSFORM')
         bpy.ops.object.select_all(action='DESELECT')
    else:
        pass


for o in bpy.context.scene.objects:
    if o.type == 'MESH':
         o.select_set(False)
    
    else:
        o.select_set(True)
        
       

bpy.ops.object.delete()

While running the script in background mode I receive the failed context error. I'm not sure how to override that context that I believe is failing because the script is running off the screen
Don't use the operator.
It is pretty simple to clear parent (set to None) and keep transform with simple API calls.
Python console code., clear parent on context object.
&gt;&gt;&gt; mw = C.object.matrix_world.copy()
&gt;&gt;&gt; C.object.parent = None
&gt;&gt;&gt; C.object.matrix_world = mw
&gt;&gt;&gt; 

Similarly, via API calls,  to remove non meshes from scene
&gt;&gt;&gt; non_meshes = [o for o in C.scene.objects if o.type != 'MESH']
&gt;&gt;&gt; non_meshes
[bpy.data.objects['Empty'], bpy.data.objects['Camera'], bpy.data.objects['Sun']]

&gt;&gt;&gt; while non_meshes:
...     D.objects.remove(non_meshes.pop())
...     
&gt;&gt;&gt; non_meshes = [o for o in C.scene.objects if o.type != 'MESH']
&gt;&gt;&gt; non_meshes
[]