On Friday, November 17, 2017 at 4:18:35 PM UTC-8, Dave S wrote:
>
>
>
> On Friday, November 17, 2017 at 1:29:55 PM UTC-8, Pierre wrote:
>>
>> No this won't work......I don't know how to instantiate a lock that will 
>> act as a global variable. this is an enigma. tried to read this:
>> http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html
>> but it's too smart for me.....what i want is '*a lock for 
>> humans*'............like 
>> it's said in the publicity
>>
>
> Distributed locks are for locking between multiple machines (like for 
> handling shards between ElasticSearch nodes).
>
> For thread safety, you only need to lock on one machine.   You can use a 
> FIFO socket or or signals (Chapter 17 of the Python docs).  Oh, and invite 
> a few philosophers to dinner.
>
> (The FIFO implementaton would be something like,
>
>      while fifo.read() != token:
>          sleep(1)
>      if fifo.read() == token:
>         do dangerous work     # keep this as short as possible
>      fifo.write(token)              # then give token back ASAP
>
> sometimes the sleep() shoud be a busy wait, but probably not for a web 
> app.  Busy waits are more common at driver level  (the last time I did 
> that, I just used atomic reads and writes on a flag
>

  [sort of a baby version of a spinlock] 

> ).
>
> Oh, and obviously the fifo needs to have token at startup.
>
>      fifo = socket(blah blah bleh)
>      fifo.open()
>      fifo.write(token)
>
> I haven't looked at your specific environment to see what extra 
> considerations are needed, and for so far for my apps it has been 
> sufficient to let the db engine handle locking (usually sqlite, which uses 
> a pretty coarse lock), so you may have holes in my advice.
>
> /dps
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to