Giter VIP home page Giter VIP logo

Comments (7)

scott-griffiths avatar scott-griffiths commented on September 25, 2024 1

Thanks. I have previously had file related problems that only occurred when unit tests were run on Windows. The error is strange though - my first thought would be that the path contains backslashes or a space that's being misinterpreted but it looks OK.

I'll try it later when I'm back in Windows-land.

from bitstring.

scott-griffiths avatar scott-griffiths commented on September 25, 2024

Hi. Thanks for the bug report. Could you provide some additional platform details on where you're running this as I'm unable to reproduce the issue? Also the contents of the traceback would be handy.

I've run your test on my Windows 11 machine (under WSL) and no exception is thrown and all the writes work for me.

Thanks.

from bitstring.

MichaelDeutschCoding avatar MichaelDeutschCoding commented on September 25, 2024

Hey Scott,
That's interesting. I wonder what I may have different about my set up?

I'm running it on Windows 11 directly (not under WSL) and this happens whether I run it interactively, in IDLE, from a terminal, or elevated terminal.

The stack trace isn't particularly helpful imo, but here ya go:

PS C:\Users\MikeD\Desktop> py .\bitstream_test.py
Traceback (most recent call last):
  File "C:\Users\MikeD\Desktop\bitstream_test.py", line 16, in <module>
    with open(path, mode='w') as f:
         ^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'some_file.txt'

And do keep in mind that previous and subsequent reads/writes within that same progam all work . When I open the file afterwards, it has the contents Final write works after deleting the bitstream.

from bitstring.

MichaelDeutschCoding avatar MichaelDeutschCoding commented on September 25, 2024

Hey @scott-griffiths , just curious -- any updates?

from bitstring.

scott-griffiths avatar scott-griffiths commented on September 25, 2024

Hi. Yes I've reproduced it locally but I don't have a fix yet. It's Windows specific and I don't have a dev environment set up to easily debug it.

I'll mark it as a bug to be fixed in 4.2, so I'll get around to it eventually! The work-around is just to read the file into memory, assuming that it's not too big, by using a BitStream instead of ConstBitStream.

from bitstring.

scott-griffiths avatar scott-griffiths commented on September 25, 2024

I'm almost certain the issue is due to the different way that Windows handles memory mapped files.

For efficiency reasons the file is accessed via a read-only mmap, which works fine on all platforms. However Windows' file system locks the file that's been mapped against writing, while Unix-like systems don't.

There's not a huge amount I can do about the underlying problem, as it's a 'feature' of the OS. I could:

  1. Opt not to use the mmap when on Windows. This isn't really a good option as it would instead break it in terms of expected performance on that OS.
  2. Document the problem. Hardly a great 'solution' (who reads the documentation?) but I'm struggling to find a better option.

I can't even make the exception more useful as it's not from my code. The OSError: Invalid argument exception is just misleading as it's not the argument that's the problem.

from bitstring.

scott-griffiths avatar scott-griffiths commented on September 25, 2024

This is now documented and so officially a 'feature' rather than a bug. Not very helpful I know but it's due to the OS, and has a poor error message from the core Python.

from bitstring.

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.