Giter Site home page Giter Site logo

Comments (9)

jensanjo avatar jensanjo commented on June 30, 2024 1

I switched to the SQLite queue. It looks like hat got rid of he issue.

from persist-queue.

jensanjo avatar jensanjo commented on June 30, 2024

Here is the test program and queue files to reproduce the problem.
qtest.tar.gz

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 30, 2024

which version are you using?

from persist-queue.

jensanjo avatar jensanjo commented on June 30, 2024

from persist-queue.

peter-wangxu avatar peter-wangxu commented on June 30, 2024

thanks, more questions:
1: which is your os kernel and the file system(ext4? xfs? and the mount info)
2: was the queue running within a container?
3: any other environment would be helpful

@jensanjo

from persist-queue.

jensanjo avatar jensanjo commented on June 30, 2024

Thanks for looking into this.

  1. The system is running mingw64 under Windows 10 Enterprise. File system: ntfs
  2. Not running within a container
  3. I have not tried to reproduce in another environment

I hope this helps!

from persist-queue.

Kryniowesegryderiusz avatar Kryniowesegryderiusz commented on June 30, 2024

Is there anything more on that? Having same error

from persist-queue.

chintal avatar chintal commented on June 30, 2024

It would be useful to know at what point the exceptions are raised (at queue creation / put / get) and to know what the exception will be. I was using pqueue which had the same issue, and I was able to work around it by catching pickle.UnpicklingError on pqueue.get_nowait(). In that case, I did not mind losing some data. It is certainly not ideal, but the data is lost by that point anyway. The exception otherwise requires manual intervention for the program to even continue operating with future data points. This manual intervention is not possible for my application.

from persist-queue.

chintal avatar chintal commented on June 30, 2024

I'm using the following wrapper class to avoid this problem. If anyone wishes to use this, you can. Note that the instantiation signature changes path from a positional arg to a keyword arg.

Note that this is exceedingly dangerous code. Not only does it assume that data loss in the queue is acceptable, it also runs shutil.rmtree without any real sanity check on what is essentially user provided input. Make sure that the path and tempdir you provide are completely disposable. Make a mistake there and you could end up accidentally wiping your entire filesystem.

import os
import shutil

class TolerantQueue(object):
    def __init__(self, name=None, logger=None, **kwargs):
        self._name = name or 'unspecified'
        self._logger = logger
        self._path = kwargs.pop('path')
        self._tempdir = kwargs.pop('tempdir', None)
        self._kwargs = kwargs
        self._create()

    def _create(self):
        if not os.path.exists(self._path):
            os.makedirs(self._path)
        if not os.path.exists(self._tempdir):
            os.makedirs(self._tempdir)
        try:
            self._actual_queue = Queue(path=self._path, tempdir=self._tempdir, **self._kwargs)
        except pickle.UnpicklingError as e:
            # info file is truncated
            if self._logger:
                self._logger.warn(f"Unpickling error ({e}) opening persisted queue "
                                  f"{self._name}. Nuking. There may be data loss.")
            self._reset()

    def _reset(self):
        self._actual_queue = None
        if self._path:
            shutil.rmtree(self._path, ignore_errors=True)
        if self._tempdir:
            shutil.rmtree(self._tempdir, ignore_errors=True)
        self._create()

    def get(self, *args, **kwargs):
        try:
            return self._actual_queue.get(*args, **kwargs)
        except (EOFError, pickle.UnpicklingError) as e:
            # q00000 like file is truncated or similar
            if self._logger:
                self._logger.warn(f"Unpickling error ({e}) reading persisted queue "
                                  f"{self._name}. Nuking. There may be data loss.")
            self._reset()
            return None

    def __getattr__(self, item):
        return getattr(self._actual_queue, item)

from persist-queue.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.