All Projects → sintezcs → flask-threads

sintezcs / flask-threads

Licence: MIT License
A helper library to work with threads in Flask

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to flask-threads

ObviousAwait
🧵 Expressive aliases to ConfigureAwait(true) and ConfigureAwait(false)
Stars: ✭ 55 (+129.17%)
Mutual labels:  multithreading
lucy job system
Fiber-based job system with extremely simple API
Stars: ✭ 78 (+225%)
Mutual labels:  multithreading
MemoryAllocator.KanameShiki
Fast multi-threaded memory allocator
Stars: ✭ 73 (+204.17%)
Mutual labels:  multithreading
theater
Actor framework for Dart. This package makes it easier to work with isolates, create clusters of isolates.
Stars: ✭ 29 (+20.83%)
Mutual labels:  multithreading
b-rabbit
A thread safe library that aims to provide a simple API for interfacing with RabbitMQ. Built on top of rabbitpy, the library make it very easy to use the RabbitMQ message broker with just few lines of code. It implements all messaging pattern used by message brokers
Stars: ✭ 15 (-37.5%)
Mutual labels:  multithreading
Multithreaded-Reddit-Image-Downloader
Does exactly what it says on the tin.
Stars: ✭ 38 (+58.33%)
Mutual labels:  multithreading
ThreadPinning.jl
Pinning Julia threads to cores
Stars: ✭ 23 (-4.17%)
Mutual labels:  multithreading
space
A SCI-FI community game server simulating space(ships). Built from the ground up to support moddable online action multiplayer and roleplay!
Stars: ✭ 25 (+4.17%)
Mutual labels:  multithreading
DynAdjust
Least squares adjustment software
Stars: ✭ 43 (+79.17%)
Mutual labels:  multithreading
Socket-Programming-Python
Client Server running code described with comments here.
Stars: ✭ 48 (+100%)
Mutual labels:  multithreading
hostbase
A Ruby GUI based on advanced rogue AP attack using the WPS
Stars: ✭ 43 (+79.17%)
Mutual labels:  multithreading
dystopia
Low to medium multithreaded Ubuntu Core honeypot coded in Python.
Stars: ✭ 59 (+145.83%)
Mutual labels:  multithreading
bikeshed
Lock free hierarchical work scheduler
Stars: ✭ 78 (+225%)
Mutual labels:  multithreading
variadic future
Variadic, completion-based futures for C++17
Stars: ✭ 41 (+70.83%)
Mutual labels:  multithreading
vmlens
unit-testing multi-threaded applications on the JVM made easy
Stars: ✭ 88 (+266.67%)
Mutual labels:  multithreading
content-downloader
Python package to download files on any topic in bulk.
Stars: ✭ 102 (+325%)
Mutual labels:  multithreading
euler2d kokkos
Simple 2d finite volume solver for Euler equations using c++ kokkos library
Stars: ✭ 27 (+12.5%)
Mutual labels:  multithreading
CoopThreads
Lightweight, platform agnostic, stackful cooperative threads library.
Stars: ✭ 18 (-25%)
Mutual labels:  multithreading
pblat
parallelized blat with multi-threads support
Stars: ✭ 34 (+41.67%)
Mutual labels:  multithreading
TradingMachine
TradingMachine is a mini-trading system simulation, whose components (market data and order feeds, FIX acceptor and initiator, back-end for filled orders) interact by queues and topics.
Stars: ✭ 26 (+8.33%)
Mutual labels:  multithreading

Flask-Threads

Actions Status

A helper library to work with threads within Flask applications.

The main problem that you face trying to spin a background thread or running a future in Flask app - is loosing the application context. The most common scenario is to try to access flask.g object. Application context is a thread local so you can not access it from another thread and Flask will raise an exception if you would try to.

This library provides helper classes that allows you accessing the current application context from another thread.

Warning! Alpha-version, use at your own risk.

Installation

$ pip install Flask-Threads

Examples

Threads

from flask import g
from flask import request
from flask import Flask
from flaskthreads import AppContextThread

app = Flask('my_app')


@app.route('/user')
def get_user():
    g.user_id = request.headers.get('user-id')
    t = AppContextThread(target=do_some_user_work_in_another_thread)
    t.start()
    t.join()
    return 'ok'


def do_some_user_work_in_another_thread():
    id = g.user_id
    print(id)

Concurrent futures

from flask import g
from flask import request
from flask import Flask
from flaskthreads import ThreadPoolWithAppContextExecutor

app = Flask('my_app')


@app.route('/user')
def get_user():
    g.user_id = request.headers.get('user-id')
    with ThreadPoolWithAppContextExecutor(max_workers=2) as pool:
        future = pool.submit(do_some_user_work_in_another_thread)
        future.result()
    return 'ok'


def do_some_user_work_in_another_thread():
    id = g.user_id
    print(id)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].