[vbox-dev] Web server and virtualbox api
Klaus Espenlaub
klaus.espenlaub at oracle.com
Fri Aug 3 08:20:52 PDT 2012
On 20.07.2012 02:55, Joao Milasch wrote:
> Hi, I have a simple web server that basically returns a screenshot or a
> particular running vm.
>
> It's an application running on top of Flask, a python MVC framework, and
> on an nginx/uwsgi web server:
[...]
> It works just fine when I run it standalone. The problem I'm having starts when I decide to host this micro-application on an nginx webserver. Again, all works fine until I enable more than one worker to listen to more request at once. Then vbox api starts throwing weird exceptions:
>
> Traceback (most recent call last):
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
> return self.wsgi_app(environ, start_response)
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
> response = self.make_response(self.handle_exception(e))
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
> response = self.full_dispatch_request()
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
> rv = self.handle_user_exception(e)
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
> rv = self.dispatch_request()
> File "/usr/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
> return self.view_functions[rule.endpoint](**req.view_args)
> File "/home/milasch/dev/nginx_test/__init__.py", line 36, in screenshot
> vm = mgr.vbox.findMachine("My VM")
> File "<XPCOMObject method'findMachine'>", line 3, in findMachine
> xpcom.Exception: 0x80470007 (Stream operation would block (NS_BASE_STREAM_WOULD_BLOCK))
You don't say a word how you create a worker. python in general is
horrible when it comes to threads, and you seem to have found that
PyXPCOM can't really deal with the situation at all.
The VirtualBox API is definitely usable by extremely multithreaded
applications, without throwing random exceptions.
> And these are kind of random, but happen 60-70% of the requests.
>
> Would this be a shared lock issue when I'm locking the VM?
Definitely not. It's exploding somewhere in the XPCOM API stubs on the
python side.
Unless you (or someone else) feels like debugging PyXPCOM and make it
thread safe, the only hacky workaround which might work is making sure
that each and every API call (everything which touches XPCOM) is
protected by a mutex. Personally I simply don't do anything in python
which relies on threads.
Klaus
>
> Please refer to:http://pastebin.com/fbWXzMMp for full uwsgi output.
>
> Any advice is appreciated.
>
>
>
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> https://www.virtualbox.org/mailman/listinfo/vbox-dev
More information about the vbox-dev
mailing list