logo
down
shadow

Django - Threading in views without hanging the server


Django - Threading in views without hanging the server

By : LSxCPU
Date : November 20 2020, 07:00 PM
I hope this helps you . But why you need thread? why can't you just do whatever you want to do in django view?
If you are using servers like apache with mod-wsgi you should be able to have good control over number of process and threads , so that part shouldn't be your worry or should not be in django views.
code :


Share : facebook icon twitter icon
Django class based views - threading issue?

Django class based views - threading issue?


By : user3219805
Date : March 29 2020, 07:55 AM
around this issue Try removing the call to super's get_initial. It's seems to use a class property instead of an instance property, causing you trouble. Try this:
code :
def get_initial(self):
    myobject = MyObject.objects.order_by('-code')[0]
    code = int(myobject.code) + 1
    initial={'code': str(code)}
    return initial
Python threading hanging?

Python threading hanging?


By : Martin Bianchi
Date : March 29 2020, 07:55 AM
will help you I do not know why it is not working but I wrote a module that you can import at the beginning of the file:
code :
import hanging_threads # https://gist.github.com/niccokunzmann/6038331
How to use threading/multiprocessing to prevent program hanging?

How to use threading/multiprocessing to prevent program hanging?


By : user2718875
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further As you are speaking of PySide, I assume you program is a GUI one. In a GUI program all processing must occurs in a worker thread if you want to keep the UI responsive. So yes, the initial script must be start in a thread distinct from main thread (main one is reserved for UI)
Django/Travis CI - configuring a .travis YAML file to first start a localhost server, then run my tests without hanging?

Django/Travis CI - configuring a .travis YAML file to first start a localhost server, then run my tests without hanging?


By : user3613358
Date : March 29 2020, 07:55 AM
it fixes the issue So silly me, after fighting for almost two days straight I figured it out. Dead simple answer and I feel stupid but I'll post it here just in case someone else who doesn't do more than simple stuff with the linux shell stumbles upon it.
I appended an ampersand to the end of the python manage.py runserver line (I'm assuming this tells the os to run this as a separate job, or to run it and proceed to the next task) and kept it in the before_script section. So the end of the .yml file looks like:
code :
before_script:
  python manage.py runserver &

script:
  coverage run manage.py tests
  coverage run functional_tests.py

after_script:
  coveralls
Threading Hanging Indefinitely

Threading Hanging Indefinitely


By : hari998598
Date : March 29 2020, 07:55 AM
To fix this issue print_number() is running an infinite loop - it never exits, so the thread never ends. It sits in number_queue_display.get() forever, waiting for another queue item that never appears. Then, since the thread never ends, printing_numbers.join() also waits forever.
So you need some way to tell the thread to quit. One common way is to put a special "sentinel" value on the queue, and have the thread exit when it sees that. For concreteness, here's a complete program, which is very much the same as what you started with. None is used as the sentinel (and is commonly used for this purpose), but any unique object would work. Note that the .task_done() parts were removed, because they no longer serve a purpose.
code :
from threading import Thread
import queue

def print_number(number_queue_display):

    while True:
        number = number_queue_display.get()
        if number is None:
            break
        print(number)


number_queue = queue.Queue()
printing_numbers = Thread(target=print_number, args=(number_queue,),)
printing_numbers.start()

number_queue.put(5)
number_queue.put(10)
number_queue.put(15)
number_queue.put(20)
number_queue.put(None)  # tell the thread it's done

printing_numbers.join() # wait for the thread to exit
Related Posts Related Posts :
  • Removing non-breaking spaces from strings using Python
  • Is there a way to backup everything in an app-engine blobstore?
  • Process a set of files from a source directory to a destination directory in Python
  • How to know if optparse option was passed in the command line or as a default
  • Rewriting a for loop in pure NumPy to decrease execution time
  • Comparing a time delta in python
  • Find next lower item in a sorted list
  • MySQLdb not INSERTING, _mysql does fine
  • Scipy Negative Distance? What?
  • What are the common patterns in web programming?
  • Percent signs in windows path
  • How to add a random number to a subsection of a numpy array?
  • How to generate all the values of an iterable besides the last few?
  • Searching by both class and range in XPath
  • Python code execution in Perl interpreter
  • Best Way to Include Variable in Python3
  • Serialize the @property methods in a Python class
  • What is the most platform- and Python-version-independent way to make a fast loop for use in Python?
  • Good way to edit the previous defined class in ipython
  • Bounced email on Google App Engine
  • Search jpeg files using python
  • Dynamically create class attributes
  • python unichr problem
  • Python beginner, strange output problem
  • Python: Finding a value in 1 list and finding that corresponding index in another list
  • can't install mysqlclient on mac os x mojave
  • Error indicates flattened dimensions when loading pre-trained network
  • how to replace underlines with words?
  • Adding through iteration
  • Use OpenCV on deployed Flask app (Heroku)
  • How to skip interstitial in a django view if a user hits the back button?
  • Any Naive Bayesian Classifier in python?
  • Python 2.5.2: remove what found between two lines that contain two concrete strings
  • Python 2.5.2 script that add "The function starts here" to all the functions of the files of a directory
  • HttpResponseRedirect question
  • Python socket error on UDP data receive. (10054)
  • Encoding issues with cloud ml
  • numpy.where - Weird behaviour: new elements spawning from nowhere?
  • I can't move my player in pygame, can you figure why?
  • Weird error I receive from Tkinter in Python
  • Using a Zapier Custom Request Webhook with JSON Web Tokens
  • Keras: Use categorical_crossentropy without one-hot encoded array of targets
  • Does python's httplib.HTTPConnection block?
  • Do alternate python implementation version numbers imply that they provide the same syntax?
  • Searching for specific HTML string using Python
  • python sax error "junk after document element"
  • MySql: How to know if an entry is compressed or not
  • Return a list of imported Python modules used in a script?
  • Returning a list in this recursive coi function in python
  • Python2.6 Decimal to Octal
  • Appengine Apps Vs Google bot web crawler
  • Changing models in django results in broken database?
  • Global variable functions
  • Using lambda inside a function
  • How to open a file, replace some strings, and save updates to the same file?
  • How to move the beginning of an input to the and?
  • If else fill variable if empty list
  • Pandas: Find and print all floats in column
  • sqlite3.OperationalError: database is locked - non-threaded application
  • How to implement mib module in net-snmp with python?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk