Is the call to unlock for the session required at all? Closing the
file unlocks the file in all cases it seems. From the doc string:
If you know what you're doing, you may choose to
   portalocker.unlock(file)
before closing the file, but why?

On Nov 28, 2:18 pm, "mr.freeze" <[email protected]> wrote:
> Yes, it still works. According to thishttp://effbot.org/librarybook/msvcrt.htm
> closing the file unlocks it so perhaps it is still getting unlocked
> since globals.py line 404-405 unlock then close it. Still doesn't
> explain the unlock error though.
>
> On Nov 28, 2:11 pm, mdipierro <[email protected]> wrote:
>
> > try print the occurrence of the exception and see if you can reload
> > the page after that.
>
> > On Nov 28, 1:31 pm, "mr.freeze" <[email protected]> wrote:
>
> > > Not that I have seen but what is a good way to test?
>
> > > On Nov 28, 12:47 pm, mdipierro <[email protected]> wrote:
>
> > > > Does this fix ever lock you out of your session?
>
> > > > Massimo
>
> > > > On Nov 28, 12:19 pm, "mr.freeze" <[email protected]> wrote:
>
> > > > > I haven't seen the session lock yet but there are many unlocking
> > > > > errors (no locking errors). I did this:
>
> > > > >     def lock(file, flags):
> > > > >         file.seek(0)
> > > > >         mode = {LOCK_NB:LK_NBLCK, LOCK_SH:LK_NBLCK, LOCK_EX:LK_LOCK}
> > > > > [flags]
> > > > >         try:
> > > > >             msvcrt.locking(file.fileno(), mode,
> > > > > os.path.getsize(file.name))
> > > > >         except IOError:
> > > > >             logger.warn('Locking error')
>
> > > > >     def unlock(file):
> > > > >         file.seek(0)
> > > > >         mode = LK_UNLCK
> > > > >         try:
> > > > >             msvcrt.locking(file.fileno(), mode,
> > > > > os.path.getsize(file.name))
> > > > >         except IOError:
> > > > >             logger.warn('Unlocking error')
>
> > > > > On Nov 27, 4:19 pm, mdipierro <[email protected]> wrote:
>
> > > > > > Here there is a thread on the topic:
>
> > > > > >http://code.activestate.com/lists/python-list/236518/
>
> > > > > > although it does not help much.
>
> > > > > > For debugging purporses.... if you replace
>
> > > > > >     msvcrt.locking(file.fileno(), mode, os.path.getsize(file.name))
>
> > > > > > with
>
> > > > > >     try: msvcrt.locking(file.fileno(), mode,
> > > > > > os.path.getsize(file.name))
> > > > > >     except IOError: pass
>
> > > > > > do you end up with a session permanently locked or does it fix the
> > > > > > problem?
>
> > > > > > Massimo
>
> > > > > > On Nov 27, 3:34 pm, "mr.freeze" <[email protected]> wrote:
>
> > > > > > > I get this occasionally on Windows 7 and Python 2.5:
>
> > > > > > > Traceback (most recent call last):
> > > > > > >   File "C:\web2py\gluon\restricted.py", line 188, in restricted
> > > > > > >     exec ccode in environment
> > > > > > >   File "C:/web2py/applications/test/models/db.py", line 66, in
> > > > > > > <module>
> > > > > > >     Field('converter')
> > > > > > >   File "C:\web2py\gluon\sql.py", line 1380, in define_table
> > > > > > >     t._create(migrate=migrate, fake_migrate=fake_migrate)
> > > > > > >   File "C:\web2py\gluon\sql.py", line 1856, in _create
> > > > > > >    portalocker.unlock(tfile)
> > > > > > >   File "C:\web2py\gluon\portalocker.py", line 78, in unlock
> > > > > > >     msvcrt.locking(file.fileno(), mode, 
> > > > > > > os.path.getsize(file.name))
> > > > > > > IOError: [Errno 13] Permission denied
>
> > > > > > > I reload the page and it goes away for a while.
>
>

Reply via email to