Il giorno 03/set/2010, alle ore 10.40, Jean-Baptiste Quenot ha scritto:
>
>
> I have defined a Python context manager for this:
>
> class UWSGILock():
> def __enter__(self):
> import uwsgi
> uwsgi.lock()
>
> def __exit__(self, exc_type, exc_val, exc_tb):
> import uwsgi
> uwsgi.unlock()
> return False
>
> I use it like this:
>
> with UWSGILock():
> doSomeExpensiveStuff()
>
> I run uwsgi like this:
>
> uwsgi -s /tmp/uwsgi.sock -M -p2 -C -i -w server --pythonpath ..
>
> However uwsgi crashes on unlock(), see attached gdb backtrace.
>
>
You need to allocate a page of shared memory to use the pthread_mutex_lock()
add -A 1 to the command line (it will allocate a shared page)
> Maybe I should refrain from using the undocumented lock() and unlock()
> functions? Any idea how I can implement UWSGI inter-process
> synchronization?
lock() and unlock() are good enough to block workers
i would want to add a try_lock() so you can avoid process blocking
and simply return and error to the client.
If it can be useful to you i can add it fast
>
> Also, is there a way to access the current UWSGI process and store
> attributes on it? I'd like to be able to attach a Memcache client to
> every UWSGI process.
>
you can create an empty global variable in you main python module,
and every worker will have its independent copy,
PROCESS_STATUS = {}
def application(env, start_response):
PROCESS_STATUS['one'] = 'two'
start_response(....)
return 'blah blah'
obviously in this way you will lost data on worker reload
--
Roberto De Ioris
http://unbit.it
JID: [email protected]
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi