whoosh-community / whoosh

Whoosh is a fast, featureful full-text indexing and searching library implemented in pure Python.
Other
245 stars 37 forks source link

LockError on Windows #558

Open maximegodin opened 4 years ago

maximegodin commented 4 years ago

Hello everyone!

I'm trying to use Whoosh on my Windows computer. The installation process works fine but I can't figure an error I'm getting.

I'm using the code snippet from the Quick start guide of the Whoosh documentation :

import whoosh.fields
import whoosh.index
import os

if __name__ == '__main__':

    schema = whoosh.fields.Schema(
        title=whoosh.fields.TEXT(stored=True), 
        content=whoosh.fields.TEXT,
        path=whoosh.fields.ID(stored=True), 
        tags=whoosh.fields.KEYWORD, 
        icon=whoosh.fields.STORED
    )

    if not os.path.exists("index"):
        os.mkdir("index")
    ix = whoosh.index.create_in("index", schema)

    writer = ix.writer()
    writer.add_document(title=u"My document", content=u"This is my document!",
                        path=u"/a", tags=u"first short", icon=u"/icons/star.png")
    writer.add_document(title=u"Second try", content=u"This is the second example.",
                        path=u"/b", tags=u"second short", icon=u"/icons/sheep.png")
    writer.add_document(title=u"Third time's the charm", content=u"Examples are many.",
                        path=u"/c", tags=u"short", icon=u"/icons/book.png")
    writer.commit()

I get the following error:

Traceback (most recent call last):
  File "whoosh_test.py", line 22, in <module>
    writer = ix.writer()
  File "C:\Users\***\AppData\Roaming\Python\Python36\site-packages\whoosh\index.py", line 464, in writer
    return SegmentWriter(self, **kwargs)
  File "C:\Users\***\AppData\Roaming\Python\Python36\site-packages\whoosh\writing.py", line 515, in __init__
    raise LockError
whoosh.index.LockError

I'm using the latest version of Whoosh (2.7.4) on Windows 10 with Python 3.6.

Does someone have any insight on this issue ?

Thanks you !

stevennic commented 4 years ago

Are you by any chance trying to write from two places simultaneously? For example, do you have two active debug sessions on this code? When your code isn't running, use Process Explorer to see if if any process has a handle on the lock file: MAIN_WRITELOCK. If so, that is the process that's holding a lock on your index. Kill the process or close the handle to release it.

If that's not it I wonder if it's some kind of permission issue on the lock file.