TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #411 · 9 фев.

reload_flag="" if [[ -n "${DEBUG}" ]]; then reload_flag="--reload" fi if [[ -n "${WORKER_COUNT}" ]]; then workers=${WORKER_COUNT} else workers=2 fi gunicorn --workers ${workers} \ --bind 0.0.0.0:8000 \ ${reload_flag} main.wsgi Писали такие конструкции чтобы проверить наличие флага и сформировать команду правильно? На самом деле можно сделать тоже самое проще. Для этого используются операторы условной подстановки, доступные в оболочках семейства POSIX. :- для установки значений по умолчанию ${WORKER_COUNT:-2} Если переменная не объявлена, то будет дефолтное значение 2. :+ подставляет указанный текст, если переменная не пуста ${DEBUG:+--reload} Если что-то есть в переменной то распечатается текст после символа +, в противном случае - ничего. Удобно для опциональных флагов, как в нашем примере. Итого наш скрипт может выглядеть так: gunicorn --workers ${WORKER_COUNT:-2} \ --bind 0.0.0.0:8000 \ ${DEBUG:+--reload} main.wsgi Есть еще два оператора. := не только подставить дефолтное значение, но и присвоить его переменной, если она пуста # никаких переменных еще нет VAL1=${VAL2:=hello} # теперь доступны обе echo $VAL1 $VAL2 # hello hello :? остановить выполнение с ошибкой, если переменной нет. echo ${MISS:?is required} bash: MISS: is required Код выхода будет 1. #tricks#linux

Резултати

Пронајдени 2 слични објави

Пребарај: #multithreading

当前筛选 #multithreading清除筛选
djangoproject

@djangoproject · Post #95 · 11.07.2016 г., 12:14

https://docs.python.org/3/library/asyncio-dev.html#asyncio-multithreading 18.5.9.3. #Concurrency and #multithreading An event loop runs in a thread and executes all callbacks and tasks in the same thread. While a task is running in the event loop, no other task is running in the same thread. But when the task uses yield from, the task is suspended and the event loop executes the next task. To schedule a callback from a different thread, the BaseEventLoop.call_soon_threadsafe() method should be used. Example: loop.call_soon_threadsafe(callback, *args) Most asyncio objects are not thread safe. You should only worry if you access objects outside the event loop. For example, to cancel a future, don’t call directly its Future.cancel() method, but: loop.call_soon_threadsafe(fut.cancel) To handle signals and to execute subprocesses, the event loop must be run in the main thread. To schedule a coroutine object from a different thread, the run_coroutine_threadsafe() function should be used. It returns a concurrent.futures.Future to access the result: future = asyncio.run_coroutine_threadsafe(coro_func(), loop) result = future.result(timeout) # Wait for the result with a timeout The BaseEventLoop.run_in_executor() method can be used with a thread pool executor to execute a callback in different thread to not block the thread of the event loop. See also The Synchronization primitives section describes ways to synchronize tasks. The Subprocess and threads section lists asyncio limitations to run subprocesses from different threads.

GitHub Trends

@githubtrending · Post #14740 · 23.05.2025 г., 12:30

#python#async#asyncio#cross_platform#downloader#gui#multithreading#pyqt#pyside6#python#qt#software#streaming Ghost Downloader 3 is a fast, AI-powered download manager that works on Windows, Linux, and macOS. It speeds up downloads by splitting files into many parts and using multiple threads, dynamically adjusting to use your full bandwidth. It supports resuming downloads, proxy settings, SSL security, and clipboard monitoring for easy link capture. The interface is modern and user-friendly. This tool helps you download files more quickly and efficiently, with options to control speed and use proxies, making it ideal if you want faster, smarter, and more reliable downloads on your computer[1]. https://github.com/XiaoYouChR/Ghost-Downloader-3