# Crashing Blender using bpy.ops.render.render from a different thread

**URL:** <https://blenderartists.org/t/crashing-blender-using-bpy-ops-render-render-from-a-different-thread/536849>\
**Category:** Python Support\
**Created:** [March 27, 2012, 9:43am UTC](https://blenderartists.org/t/crashing-blender-using-bpy-ops-render-render-from-a-different-thread/536849 "2012-03-27T09:43:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Irgi](https://blenderartists.org/letter_avatar_proxy/v4/letter/i/9fc29f/32.png) [@Irgi](https://blenderartists.org/u/Irgi)\
**Post date:** [March 27, 2012, 9:43am UTC](https://blenderartists.org/t/crashing-blender-using-bpy-ops-render-render-from-a-different-thread/536849/1 "2012-03-27T09:43:29Z")

</div>

I’m started to control blender (2.61) using a little webserver script and sending commands to it from a browser. It’s running fine for changing object locations.  
But as soon as i call bpy.ops.render.render from the script, blender crashes.  
Any idea how to solve this?  
Thanks,  
Stephan

```auto

import threading
import http.server
import socketserver
from urllib.parse import urlparse
import time
import bpy

PORT = 8000
IP_ADDRESS = "localhost"
#IP_ADDRESS = "192.168.254.1"
global running
running = 1

class RequestHandler(http.server.BaseHTTPRequestHandler):
    def _writeheaders(self):
      self.send_response(200)
      self.send_header('Content-type', 'text/html; charset=UTF-8')
      self.end_headers()
    
    def do_HEAD(self):
      self._writeheaders()
        
    def do_GET(self):
      global running  
      parsed_path = urlparse(self.path)
      #ctx = bpy.context.active_object
      #print(ctx)
      
      #bpy.ops.screen.screenshot(filepath="c:\	emp\	est8.bmp")
      try:
        params = dict([p.split('=') for p in parsed_path[4].split('&')])
      except:
        params = {}
      print(params)    
      try:
        running = int(params["running"])
      except:
        running = 1
      try:
        print("Here i am")
        #Here it crashes!
        bpy.ops.render.render(write_still=True)
      except:
        print("no xrot")      
      self._writeheaders()
      retstr = """&lt;HTML&gt;
&lt;HEAD&gt;&lt;TITLE&gt;Dummy response&lt;/TITLE&gt;&lt;/HEAD&gt;
&lt;BODY&gt;dummy response&lt;/BODY&gt;
&lt;/HTML&gt;"""
      self.wfile.write(retstr.encode('latin'))
      print("running = ",running) 

    
httpd = socketserver.TCPServer((IP_ADDRESS, PORT), RequestHandler)

class HttpThread(threading.Thread):
  def __init__ (self):
    threading.Thread. __init__ (self)
  def run(self):
    print("HTTP Server THREAD: started")
    print("serving at port", PORT)
    httpd.serve_forever()
    print ("HTTP Server THREAD: finished")
      
class ControlThread(threading.Thread):
  def __init__ (self):
    threading.Thread. __init__ (self)
  def run(self):
    print("Control THREAD: started")
    runcontrol = 1    
    while runcontrol &gt;0:
      if running &lt; 1:
        print("try server shutdown")
        httpd.shutdown()
        httpd.socket.close() 
        print("shutdown finished")
        runcontrol = 0
      time.sleep(1)                
        
    print ("Control THREAD: finished")
            
print ("SCRIPT: started")    
http_thread = HttpThread()
http_thread.start()

control_thread = ControlThread()
control_thread.start()
print ("SCRIPT: finished") 

```

---

<div class="post-metadata">

**Author:** ![Atom](https://blenderartists.org/user_avatar/blenderartists.org/atom/32/2832_2.png) [@Atom](https://blenderartists.org/u/Atom)\
**Post date:** [March 27, 2012, 12:03pm UTC](https://blenderartists.org/t/crashing-blender-using-bpy-ops-render-render-from-a-different-thread/536849/2 "2012-03-27T12:03:10Z")

</div>

You might want to read up on the API gotchas.  
[http://www.blender.org/documentation/blender\_python\_api\_2\_62\_2/search.html?q=gotchas&check\_keywords=yes&area=default](http://www.blender.org/documentation/blender_python_api_2_62_2/search.html?q=gotchas&check_keywords=yes&area=default)

Blender does not play well with threading.  
The _context_ is always None when rendering.
