Code Monkey home page Code Monkey logo

Comments (2)

aaugustin avatar aaugustin commented on May 18, 2024

If two threads run this code concurrently, thread 2 will block on the get_next_value call and won't start executing # Code B until thread 1 finishes executing # Code C.

This is fairly easy to test by replacing # Code X with print("enter X"); time.sleep(10); print("exit X") and running the script in two terminals side by side.

If you try it, I'm interested in a confirmation that the behavior is indeed what I predicted.

PS - if you enabled the ATOMIC_REQUESTS option (which you probably did if you care enough about transactions to look at django-sequences) then the outer atomic block is created by Django and wraps the entire view.

from django-sequences.

pkaczynski avatar pkaczynski commented on May 18, 2024

Thanks for the reply. I can confirm your elaboration. I tested it "manually" using debugger and indeed, thread 2 would block until Code C is fully executed. It works like nesting atomic blocks.

And as to your PS - I did not enable ATOMIC_REQUESTS, and did it deliberately. I do not want requests to be atomic. This is actually the only case I need locking and syncing between requests. I do not want to loose performance :]

Thanks again for the clarification!

from django-sequences.

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.