[web2py] Re: threading Lock

2017-11-21 Thread Pierre
well, i am not very religious but i think i'll have to pray anyway or throw 
everything to the 'fire' as a disaster prevention 
policy.just kidding
let's be optimistic and believe in something..i like matplotlib but i 
prefer visual python: it is capable to display content on a website too

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-20 Thread Leonel Câmara


Pretty much. Note that usually you can refer to the library documentation 
to know which parts are threadsafe. For instance matplotlib has an 
object-oriented interface that is thread safe as it is explained here:

https://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server





-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-20 Thread Pierre
 

from recent forum threads elements i assume the following  
'macro-situation':


(0) python libraries selected for a project should be thread-safe

(1) user uses python libaries at his own risk (there 's no mean to verify 
it's thread-safe)

(2) in order to minimize risks user should put a lock around all code using 
the libraries :


def dangerous() :
 with lock_libraryA : 
 do something with libraryA 
 with lock_libraryB : 
 do something with libraryB



(3) in case of application crashes where libraries are involved means 
libraries cannot be used and designers should look for alternatives 


is this correct ?


As regard the dangerous code 'micro-situation': 

I think it' ll be ok to lock between threads. One line of code instantiates 
the main library object (constructor takes 2 files arguments). Is that a 
potential problem at the process level ? (code is readonly nothing is  ever 
written to the files)


As regard processes concurrency :

Doing tests with several scheduler processes and lot's of tasks, i have had 
deadlocks so i wondered if postgreSQL Lock command could help prevent that ?

https://www.tutorialspoint.com/postgresql/postgresql_locks.htm



thanks guys for your support……. 



 @Dave : quote by Nietzsche 

« Partout on entend la voix de ceux qui prêchent la mort : et la terre est 
pleine de ceux à qui il convient de prêcher la mort. »




-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-18 Thread Leonel Câmara
Do you want to lock between processes or just threads? If it's just between 
threads you can just put the lock in a module instead of a model file. 
Models are executed again on every request so you're creating a new Lock 
each time so threads will be locking different lock instances. Between 
processes you can use Dave's suggestion or you can use portalocker which 
web2py includes.

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-17 Thread Dave S


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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-17 Thread Dave S


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).

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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: threading Lock

2017-11-17 Thread Pierre
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

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.