python-multithreading

Python update Matplotlib from threads

廉价感情. 提交于 2019-12-03 22:25:00
问题 I'm pretty new to the python world and unfortunately I could not find any solution to this yet. I'm running python 3.6 with matplotlib==1.3.1 on Mac OS X 10.13.2 Currently I'm trying to build a small software which fetches data at 4Hz and displays the fetched data in a plot at 1Hz. Therefore I created a class which runs in a thread to fetch the data and another class to update the actual plots. In-between there is a data class which will hold the data and is used as interface inbetween the

Chunksize irrelevant for multiprocessing / pool.map in Python?

心已入冬 提交于 2019-12-03 21:01:44
I try to utilize the pool multiprocessing functionality of python. Independent how I set the chunk size (under Windows 7 and Ubuntu - the latter see below with 4 cores), the amount of parallel threads seems to stay the same. from multiprocessing import Pool from multiprocessing import cpu_count import multiprocessing import time def f(x): print("ready to sleep", x, multiprocessing.current_process()) time.sleep(20) print("slept with:", x, multiprocessing.current_process()) if __name__ == '__main__': processes = cpu_count() print('-' * 20) print('Utilizing %d cores' % processes) print('-' * 20)

Python Celery versus Threading Library for running async requests [closed]

℡╲_俬逩灬. 提交于 2019-12-03 15:43:51
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I am running a python method that parses a lot of data. Since it is time intensive, I would like to run it asynchronously on a separate thread so the user can still access the website/UI. Do threads using the "from threading import thread" module terminate if a user exits the

How can I have multiple clients on a TCP Python Chat Server?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 14:40:56
Any help on how I can get this to accept more than one client, and why it isn't at the moment? Thanks! Also, is there anything I'm doing wrong with this code? I've been following mostly Python 2 tutorials because I can't find any for Python 3.4 Here is my Server code: import socket import time import os from threading import Thread folderPath = "Chat Logs" filePath = folderPath + "/" + str(time.strftime("%H-%M-%S_%d-%m-%Y")) + ".txt" def clientHandler(c): while True: data = c.recv(1024) if not data: break data = data.decode("UTF-8") message = str(data[:data.index("§")]) nick = str(data[data

How to stop daemon thread?

左心房为你撑大大i 提交于 2019-12-03 10:01:21
问题 I have a simple producer consumer application. The producer is a thread that writes stuff to a queue and a consumer is a thread that reads the messages from the queue does stuff and at some points exits. my producer looks a little bit like this def producer(queue): while not queue.full(): queue.put(randint(1, 199)) and the consumer def consumer(queue): for i in range(100): print(queue.get()) queue.task_done() in my main I invoke those threads like that p = Thread(target=producer) c = Thread

combining python watchdog with multiprocessing or threading

廉价感情. 提交于 2019-12-03 07:09:01
I'm using Python's Watchdog to monitor a given directory for new files being created. When a file is created, some code runs that spawns a subprocess shell command to run different code to process this file. This should run for every new file that is created. I've tested this out when one file is created, and things work great, but am having trouble getting it working when multiple files are created, either at the same time, or one after another. My current problem is this... the processing code run in the shell takes a while to run and will not finish before a new file is created in the

Python Celery versus Threading Library for running async requests [closed]

醉酒当歌 提交于 2019-12-03 06:10:32
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . I am running a python method that parses a lot of data. Since it is time intensive, I would like to run it asynchronously on a separate thread so the user can still access the website/UI. Do threads using the "from threading import thread" module terminate if a user exits the site or do they continue to run on the server? What would be the advantages of using Celery versus simply

Is extending a Python list (e.g. l += [1]) guaranteed to be thread-safe?

喜你入骨 提交于 2019-12-03 04:54:20
问题 If I have an integer i , it is not safe to do i += 1 on multiple threads: >>> i = 0 >>> def increment_i(): ... global i ... for j in range(1000): i += 1 ... >>> threads = [threading.Thread(target=increment_i) for j in range(10)] >>> for thread in threads: thread.start() ... >>> for thread in threads: thread.join() ... >>> i 4858 # Not 10000 However, if I have a list l , it does seem safe to do l += [1] on multiple threads: >>> l = [] >>> def extend_l(): ... global l ... for j in range(1000):

How to stop daemon thread?

荒凉一梦 提交于 2019-12-03 00:32:22
I have a simple producer consumer application. The producer is a thread that writes stuff to a queue and a consumer is a thread that reads the messages from the queue does stuff and at some points exits. my producer looks a little bit like this def producer(queue): while not queue.full(): queue.put(randint(1, 199)) and the consumer def consumer(queue): for i in range(100): print(queue.get()) queue.task_done() in my main I invoke those threads like that p = Thread(target=producer) c = Thread(target=consumer) p.daemon = True p.start() c.start() c.join() when c finishes the only remaining non

HTTP Requests using a range of IP address on python

落花浮王杯 提交于 2019-12-02 22:34:40
问题 I have a VM as a server with IP address 10.91.55.2. I have another VM which acts as a client having IP address in the range 10.91.56.2......10.91.56.10. I want to write a script that will use all these IP address on the client to send HTTP request to the server (10.91.55.2). I have written a script that sends HTTP requests using the Physical IP address alone. Is there any way to send HTTP Requests from a range of IP address. My OS Is linux. 回答1: This is not a complete answer, but should