python-multithreading

Do threads in python need to be joined to avoid leakage?

给你一囗甜甜゛ 提交于 2020-08-27 02:39:48
问题 I understand the purpose of joining a thread, I'm asking about resource use. My specific use-case here is that I have a long-running process that needs to spawn many threads, and during operation, checks if they have terminated and then cleans them up. The main thread waits on inotify events and spawns threads based on those, so it can't block on join() calls, because it needs to block on inotify calls. I know that with pthreads, for instance, not joining a terminated thread will cause a

Python Multiprocessing: TypeError: __new__() missing 1 required positional argument: 'path'

对着背影说爱祢 提交于 2020-08-24 08:17:13
问题 I'm currently trying to run a parallel process in python 3.5 using the joblib library with the multiprocessing backend. However, every time it runs I get this error: Process ForkServerPoolWorker-5: Traceback (most recent call last): File "/opt/anaconda3/lib/python3.5/multiprocessing/process.py", line 249, in _bootstrap self.run() File "/opt/anaconda3/lib/python3.5/multiprocessing/process.py", line 93, in run self._target(*self._args, **self._kwargs) File "/opt/anaconda3/lib/python3.5

python thread not exiting with atexit

橙三吉。 提交于 2020-07-23 06:50:16
问题 Here is my script. When I run it in a shell it just hangs indefinitely whereas I would expect it to terminate cleanly. import logging from logging import StreamHandler import pymsteams import queue import threading import atexit class TeamsHandler(StreamHandler): def __init__(self, channel_url): super().__init__() self.channel_url = channel_url self.queue = queue.Queue() self.thread = threading.Thread(target=self._worker) self.thread.start() atexit.register(self.queue.put, None) def _worker

python thread not exiting with atexit

吃可爱长大的小学妹 提交于 2020-07-23 06:49:08
问题 Here is my script. When I run it in a shell it just hangs indefinitely whereas I would expect it to terminate cleanly. import logging from logging import StreamHandler import pymsteams import queue import threading import atexit class TeamsHandler(StreamHandler): def __init__(self, channel_url): super().__init__() self.channel_url = channel_url self.queue = queue.Queue() self.thread = threading.Thread(target=self._worker) self.thread.start() atexit.register(self.queue.put, None) def _worker

Run dependent threads simultaneously in Python

守給你的承諾、 提交于 2020-07-10 03:38:28
问题 I have two thread classes extract and detect. Extract extracts frames from a video and stores it in a folder, Detect takes images from the folder where frames are extracted and detects objects. But when I run the below code only the extract works: global q q = Queue() class extract(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): print("T1") cam = cv2.VideoCapture(video_name) frameNum = 0 # isCaptured = True frameCount = 0 while True: isCapture, frame =

Progress Bar Does not Render Until Job is Complete

风格不统一 提交于 2020-06-28 07:43:46
问题 I am trying to make a progress bar for copying large files. However, currently the Dialog window goes black until the process is finished. I now understand I probably have to learn how to use treads and pass the data back into the GUI. But I still don't understand why the window fails to render completely. I'd understand if the window was unresponsive because the moveFilesWithProgress function is running. But within that function I am updating the progress bar value. I even tried adding QtGui

Check if Timer.cancel is called in unit test

回眸只為那壹抹淺笑 提交于 2020-06-27 15:45:13
问题 I'm using the threading.Timer package to execute a method after x seconds. However, in some cases I want to execute this method earlier and cancel the timer (so it isn't called twice). How do I unit test this? I want to know if the timer has stopped so that the method is not called anymore. I am now using the following code, unfortunately the is_alive still returns True from threading import Timer Class X(): def __init__(self, timeout): self.timer = Timer(timeout, self.some_method) self.timer