Question

I am messing around with XMPP in Python, and I want to be able to spawn new processes to listen for messages over XMPP. I figured that I would use gevent to spawn new processes to listen for messages.

I am just trying to write messages to a simple SQLite3 database just to track what is going on, however messages are only written to the database for one user. I am sure I am just not getting how gevent works.

Here is the code. https://gist.github.com/simonbowen/6756511

Was it helpful?

Solution

You need to activate gevent monkey-patching. It will make Python code like from the SleekXMPP library 'non-blocking', and you will be able to process multiple greenlets in parallel. Just add the following line after gevent import:

from gevent import monkey; monkey.patch_all()

However, it seems to me calls to sqlite3 will still be blocking, since I suppose it is a Python extension module written in C. If you want to go for a full gevent-friendly implementation, you have to make calls to sqlite3 in a separate thread, for example, using gevent threadpool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top