multithreading

Unresponsive requests- understanding the bottleneck (Flask + Oracle + Gunicorn)

[亡魂溺海] 提交于 2021-01-28 08:03:50
问题 I'm new to Flask/Gunicorn and have a very basic understanding of SQL. I have a Flask app that connects to a remote oracle database with cx_oracle. Depending on the app route selected, it runs one of two queries. I run the app using gunicorn -w 4 flask:app . The first query is a simple query on a table with ~70000 rows and is very responsive. The second one is more complex, and queries several tables, one of which contains ~150 million rows. Through sprinkling print statements around, I notice

How to parallelize a program that need 0.005 seconds to terminate sequentially?

心已入冬 提交于 2021-01-28 08:03:21
问题 for a project i need to parallelize a sudoku solver, that sequentially terminate in avarage in 0.005 seconds. For test i also count how many "computations" the program does to solve the sudoku, and the problem is that when i run it in multithreading, if i do a lot less "computations" of the sequential version, then the completion time of the program in multithreading is less than the sequential version, but if the sequential version does for instance 2000 computations to solve the sudoku, and

How to cancel a task using a CancellationToken and await Task.WhenAny

浪子不回头ぞ 提交于 2021-01-28 07:54:32
问题 I have web application and it calls different web service to perform different work. Some web services will take long time and some short. Application will call all web services parallel to get result when complete or exception. I have started to write code but i need to know how to implement the following works in the best way. A task will be cancelled if any of web service takes more than 5 seconds but remaining tasks will continue to call web service to get either result or excepton. I

Python multiprocessing queue is empty although it is filled in a different thread

删除回忆录丶 提交于 2021-01-28 07:33:04
问题 I have now tried to resolve this issue for multiple hours but no matter what I do, I never get the thing to work. My project tracks live data and provides an endpoint for other services to get the latest(ish) measurement. But no matter what I do, the queue.get() always returns nothing. Here is my code: from collections import deque import numpy as np import argparse import imutils import cv2 from flask import Flask from multiprocessing import Queue import threading import Queue as Q app =

Calling java method from different thread in ndk

倖福魔咒の 提交于 2021-01-28 07:08:35
问题 I'm trying to call a java static method from a detached thread in c++ with android's NDK. So far I've : JNIEnv *env =AttachJava(); jclass cls2 = env->FindClass("com/actvt/showdown/pluggin/Utils"); // try to find the class //jmethodID mid2 = env->GetStaticMethodID(cls2, "AddSound", "(Landroid/app/Activity;Ljava/lang/String;I)V"); // find method jmethodID mid = env->GetStaticMethodID(cls2, "addFrame", "(Landroid/app/Activity;JIIII)V"); // find method jclass dataClass = env->FindClass("android

interrupt System.console().readLine()?

柔情痞子 提交于 2021-01-28 06:38:27
问题 It seems to me that once a thread starts reading input via System.console().readLine() or System.in.read() , there is absolutely no way in the universe to functionally interrupt the read, except for System.exit() or providing input. interrupt() ing the reading thread does nothing. Even stop() ing it does nothing. close() ing System.in during System.in.read() does nothing until after the read completes by providing input. The read methods don't take any timeout parameters nor time out on their

Correct way to handle task cancelation

橙三吉。 提交于 2021-01-28 06:34:28
问题 I am experiencing some weird behaviour with a windows service application I am working on. This is my 1st dip into Tasks so I am on a steep learning curve and in need of some assistance as I know my issue is probably down to something I have misunderstood. I have the following setup: public partial class MyService { protected override void OnStart(string[] args) { MasterTokenSource = new CancellationTokenSource(); MasterCancellationToken = MasterTokenSource.Token; //Begin tasks. StartAllTasks

Initialising with std::call_once() in a multithreading environment [duplicate]

霸气de小男生 提交于 2021-01-28 06:32:54
问题 This question already has an answer here : Is std::call_once a blocking call? (1 answer) Closed 1 year ago . I'm reading the book C++ Concurrency in Action, 2nd Edition X . The book contains an example that uses the std::call_once() function template together with an std::once_flag object to provide some kind of lazy initialisation in thread-safe way. Here a simplified excerpt from the book: class X { public: X(const connection_details& details): connection_details_{details} {} void send_data

Reference of graphics 2d object doesn't work in orphan Thread

回眸只為那壹抹淺笑 提交于 2021-01-28 06:23:51
问题 I am trying to design a simple game using Graphics2D in a JPanel. I am able to draw normal objects by overriding the paintComponent() method. But when I reference the Graphics2D object inside a orphan Thread, it does not work. Where am I going wrong? public void paintComponent(Graphics g) { super.paintComponent(g); g2d = (Graphics2D) g; g2d.drawString("sample",60,100); //Works fine if(<Certain Condition>){ new Thread(new Runnable(){ //Some Code Here public void run() { try{ g2d.drawString(

Task based vs. thread based Watchdog - but async needed

断了今生、忘了曾经 提交于 2021-01-28 06:13:32
问题 We're using watchdogs to determine whether a connected system is still alive or not. In the previous code we used TCP directly and treated the watchdog in a separate thread. Now is a new service used that provides it's data using gRPC. For that we tried using the async interface with tasks but a task based watchdog will fail. I wrote a small DEMO that abstracts the code and illustrates the problem. You can switch between task based watchdog and thread based watchdog by commenting out line 18