2010/9/3 Roberto De Ioris <[email protected]>:
>
> 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)
Nice it works. How can I create an account to mention lock() and
unlock() in the wiki?
>> 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
That's a good trick! Actually I thought about using a global module
attribute, but not this way. I didn't realize I had a copy, I thought
it was the same reference.
Cheers,
--
Jean-Baptiste Quenot
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi