Re: Multithreading? How?

2023-05-12 Thread Diego Souza
Hi there, I hope this e-mail is still on time for you. I have implemented this architecture a few times, and they all work fine nowadays. However, your question made me review it and create a small gist. I suggest you create a thread for every output and input connection. This makes it easier to

Re: Multithreading python,two tkinter windows

2015-11-01 Thread Terry Reedy
On 11/1/2015 9:05 AM, Vindhyachal Takniki wrote: I have made a python code & using multithreading in it. this is very basic code, not using queues & other stuff. You can run multiple windows, or one window with multiple panes, in one thread with one event loop. Best to do gui stuff in the ma

Re: Multithreading python,two tkinter windows

2015-11-01 Thread Chris Angelico
On Mon, Nov 2, 2015 at 1:05 AM, Vindhyachal Takniki wrote: > #get reading at every 1 second > def get_analog_1(thread_name): > global read_ok_1, current_time_1,analog_1 > while True: > if((time.time() - current_time_1) > 1): > if(0 == read_ok_1): > curre

Re: Multithreading python,two tkinter windows

2015-11-01 Thread Laura Creighton
In a message of Sun, 01 Nov 2015 06:05:58 -0800, Vindhyachal Takniki writes: >I have made a python code & using multithreading in it. this is very basic >code, not using queues & other stuff. This is your problem. The code that uses queues is more basic. For tkinter you cannot use threads like yo

Re: multithreading in python

2013-08-13 Thread Terry Reedy
On 8/13/2013 4:06 AM, samaneh.yahyap...@gmail.com wrote: Aside from the other comments... def item_thread(self): imageAnalyzer=ctypes.CDLL("../so/image_process.so") imageAnalyzer.aref_img_score_init("/opt/amniran/etc/face.xml", "/opt/amniran/etc/porn.xml") for f

Re: multithreading in python

2013-08-13 Thread Dave Angel
samaneh.yahyap...@gmail.com wrote: > hi > my program work by 4 thread but when i use more thread it terminates > > how can i solve this problem I simplified the code so I could actually run it, and tested it in Python 2.7, both under Komodo IDE and in the terminal. The code: #!/usr/bin/en

Re: multithreading in python

2013-08-13 Thread Dave Angel
samaneh.yahyap...@gmail.com wrote: > hi > my program work by 4 thread but when i use more thread it terminates > > I simplified your code so anybody could run it, and tested it inside Komodo IDE, on Python 2.7 #!/usr/bin/env python import sys import os import time import threading class MyC

Re: multithreading in python

2013-08-13 Thread Steven D'Aprano
On Tue, 13 Aug 2013 01:06:01 -0700, samaneh.yahyapour wrote: > hi > my program work by 4 thread but when i use more thread it terminates Is that a problem? Isn't it supposed to terminate, when it has finished? If it raises an exception, or crashes, you should tell us. > i use opencv in my ima

Re: multithreading

2012-04-08 Thread Bryan
Kiuhnm wrote: > I have a decorator which takes an optional argument that tells me > whether I should use locks. > Maybe I could import 'threading' only if needed. If the user wants to > use locks I'll assume that 'threading' is available on his/her system. Use of dummy_threading might be cleaner.

Re: multithreading

2012-04-08 Thread Kiuhnm
On 4/8/2012 7:04, Bryan wrote: Kiuhnm wrote: My question is this: can I use 'threading' without interfering with the program which will import my module? Yes. The things to avoid are described at the bottom of: http://docs.python.org/library/threading.html On platforms without threads, 'impor

Re: multithreading

2012-04-07 Thread Bryan
Kiuhnm wrote: > My question is this: can I use 'threading' without interfering with the > program which will import my module? Yes. The things to avoid are described at the bottom of: http://docs.python.org/library/threading.html On platforms without threads, 'import threading' will fail. There's

Re: multithreading

2012-04-07 Thread Adam Skutt
On Apr 7, 5:06 pm, Kiuhnm wrote: > On 4/7/2012 22:09, Bryan wrote:>> For instance, let's say I want to make this > code thread-safe: > > >> ---> > >> myDict = {} > > >> def f(name, val): > >>       if name not in myDict: > >>           myDict[name] = val > >>       return myDict[name] > >> <--- >

Re: multithreading

2012-04-07 Thread Kiuhnm
On 4/7/2012 22:09, Bryan wrote: For instance, let's say I want to make this code thread-safe: ---> myDict = {} def f(name, val): if name not in myDict: myDict[name] = val return myDict[name] <--- First, don't re-code Python's built-ins. The example is a job for dict.setd

Re: multithreading

2012-04-07 Thread Bryan
Kiuhnm wrote: > I'm about to write my first module and I don't know how I should handle > multithreading/-processing. > I'm not doing multi-threading inside my module. I'm just trying to make > it thread-safe so that users *can* do multi-threading. There are a couple conventions to follow. Trying

Re: Multithreading

2011-12-26 Thread Ian Kelly
On Dec 26, 2011 4:13 PM, "Yigit Turgut" wrote: > Why is there N variable in write_data function ? N is related to > timer.tick(N) which is related to display function ? time.sleep(N) > will pause writing to file for specified amount of time which is > exactly what I am trying to avoid. My underst

Re: Multithreading

2011-12-26 Thread Yigit Turgut
On Dec 26, 10:01 pm, Ian Kelly wrote: > On Mon, Dec 26, 2011 at 11:31 AM, Yigit Turgut wrote: > > I have a loop as following ; > > > start = time.time() > > end = time.time() - start > >  while(end >          data1 = self.chan1.getWaveform() > >          end = time.time() - start > >          tim

Re: Multithreading

2011-12-26 Thread Ian Kelly
On Mon, Dec 26, 2011 at 1:13 PM, Yigit Turgut wrote: > I had thought the same workaround but unfortunately loop is already > under a def ; So nest the functions, or refactor it. Either way, that shouldn't be a significant obstacle. -- http://mail.python.org/mailman/listinfo/python-list

Re: Multithreading

2011-12-26 Thread Yigit Turgut
On Dec 26, 10:03 pm, Ian Kelly wrote: > On Mon, Dec 26, 2011 at 1:01 PM, Ian Kelly wrote: > > You essentially have two completely independent loops that need to run > > simultaneously with different timings.  Sounds like a good case for > > multiple threads (or processes if you prefer, but these

Re: Multithreading

2011-12-26 Thread Ian Kelly
On Mon, Dec 26, 2011 at 1:01 PM, Ian Kelly wrote: > You essentially have two completely independent loops that need to run > simultaneously with different timings.  Sounds like a good case for > multiple threads (or processes if you prefer, but these aren: I accidentally sent before I was finishe

Re: Multithreading

2011-12-26 Thread Ian Kelly
On Mon, Dec 26, 2011 at 11:31 AM, Yigit Turgut wrote: > I have a loop as following ; > > start = time.time() > end = time.time() - start >  while(end          data1 = self.chan1.getWaveform() >          end = time.time() - start >          timer.tick(10)  #FPS >          screen.fill((255,255,255)

Re: multithreading, performance, again...

2010-01-18 Thread Oktaka Com
On 30 Aralık 2009, 17:44, mk wrote: > Hello everyone, > > I have figured out (sort of) how to do profiling of multithreaded > programs with cProfile, it goes something like this: > > #!/usr/local/bin/python > > import cProfile > import threading > > class TestProf(threading.Thread): >      def __i

Re: multithreading, performance, again...

2009-12-31 Thread Antoine Pitrou
> 39123 function calls (38988 primitive calls) in 6.004 CPU > seconds > [...] > > It's not burning CPU time in the main thread (profiling with cProfile > indicated smth similar to the above), it's not burning it in the > individual worker threads What do you mean, it's not b

Re: multithreading in python

2009-05-12 Thread Almar Klein
See the standard help on the threading and thread module. Almar 2009/5/12 shruti surve : > hi, >  how to do multithreading in python??? Like running dialog box and running > xml rpc calls simultaneously??? > > > regards > shruti > > -- > http://mail.python.org/mailman/listinfo/python-list > > --

Re: Multithreading / multiprocess

2009-04-12 Thread TennesseeLeeuwenburg
On Apr 12, 2:59 am, a...@pythoncraft.com (Aahz) wrote: > In article > <57065c62-2024-47b5-a07e-1d60ff85b...@y10g2000prc.googlegroups.com>, > > tleeuwenb...@gmail.com wrote: > > >Is there anyway to begin a thread and execute a finite number of lines > >of code, or a finite amount of time within it

Re: Multithreading / multiprocess

2009-04-12 Thread TennesseeLeeuwenburg
On Apr 11, 10:39 pm, "Diez B. Roggisch" wrote: > tleeuwenb...@gmail.com schrieb: > > > Is there anyway to begin a thread and execute a finite number of lines > > of code, or a finite amount of time within it? > > > For example, say I create three child threads and I want to guarantee > > equal tim

Re: Multithreading / multiprocess

2009-04-11 Thread Aahz
In article <57065c62-2024-47b5-a07e-1d60ff85b...@y10g2000prc.googlegroups.com>, tleeuwenb...@gmail.com wrote: > >Is there anyway to begin a thread and execute a finite number of lines >of code, or a finite amount of time within it? > >For example, say I create three child threads and I want to gua

Re: Multithreading / multiprocess

2009-04-11 Thread Diez B. Roggisch
tleeuwenb...@gmail.com schrieb: Is there anyway to begin a thread and execute a finite number of lines of code, or a finite amount of time within it? For example, say I create three child threads and I want to guarantee equal timeshare between them, can I specify a quanta (say 400 LOC although I

Re: multithreading in python ???

2008-07-10 Thread Kris Kennaway
Laszlo Nagy wrote: Abhishek Asthana wrote: Hi all , I have large set of data computation and I want to break it into small batches and assign it to different threads .I am implementing it in python only. Kindly help what all libraries should I refer to implement the multithreading in pytho

Re: multithreading in python ???

2008-07-03 Thread mimi.vx
On Jul 3, 12:40 pm, Laszlo Nagy <[EMAIL PROTECTED]> wrote: > Abhishek Asthana wrote: > > > Hi all , > > > I  have large set of data computation and I want to break it into > > small batches and assign it to different threads .I am implementing it > > in python only. Kindly help what all libraries s

Re: multithreading in python ???

2008-07-03 Thread Laszlo Nagy
Abhishek Asthana wrote: Hi all , I have large set of data computation and I want to break it into small batches and assign it to different threads .I am implementing it in python only. Kindly help what all libraries should I refer to implement the multithreading in python. You should not

Re: multithreading concept

2007-03-08 Thread Paul Rubin
"Paul Boddie" <[EMAIL PROTECTED]> writes: > What makes all of the following not "Pythonic"...? > http://wiki.python.org/moin/ParallelProcessing I'd say mainly that they don't allow sharing data between processes except through expensive IPC mechanisms involving system calls. > I'm sure one could

Re: multithreading concept

2007-03-08 Thread Paul Boddie
On 8 Mar, 10:48, Bryan Olson <[EMAIL PROTECTED]> wrote: > > That doesn't really work in Python. There have been projects to > allow Pythonic coordination of processes -- POSH had some good > ideas -- but none have reached fruition. What makes all of the following not "Pythonic"...? http://wiki.py

Re: multithreading concept

2007-03-08 Thread Bryan Olson
sturlamolden wrote: [...] > If you want to utilize the computing power of multiple CPUs, you > should use multiple processes instead of threads. On Python this is > mandatory due to the GIL. In any other language it it highly > recommended. The de-factor standard for parallel multiprocessing (MPI)

Re: multithreading concept

2007-02-10 Thread Bjoern Schliessmann
Carl J. Van Arsdall wrote: > Not necessarily, if he's on a full duplex ethernet connection, > then there is some parallelity he can take advantage of. He has > upstream and downstream. Partly agreed. There is one bus to the network device, and CPU should be very much faster than the network devi

Re: multithreading concept

2007-02-09 Thread sturlamolden
On Feb 9, 4:00 pm, "S.Mohideen" <[EMAIL PROTECTED]> wrote: > I am sorry if I sound foolish. > Suppose I split my Net application code using parallel python into several > processes based upon the number of CPU available. That means a single socket > descriptor is distributed across all processes.

Re: multithreading concept

2007-02-09 Thread Paul Rubin
"S.Mohideen" <[EMAIL PROTECTED]> writes: > Suppose I split my Net application code using parallel python into > several processes based upon the number of CPU available. That means a > single socket descriptor is distributed across all processes. Is > parallelity can be acheived using the processes

Re: multithreading concept

2007-02-09 Thread S.Mohideen
the single socket multiplexed across all the processes.. I haven't tried it yet - would like to have any past experience related to this. - Original Message - From: "Carl J. Van Arsdall" <[EMAIL PROTECTED]> To: Sent: Thursday, February 08, 2007 3:44 PM Subjec

Re: multithreading concept

2007-02-08 Thread Carl J. Van Arsdall
Bjoern Schliessmann wrote: > [snip] > What makes you think that'll be faster? > > Remember: > - If you have one CPU, there is no parallelity at all. > - If you do have multiple CPUs but only one network device, there is > no parallel networking. > > Not necessarily, if he's on a full duplex ethe

Re: multithreading concept

2007-02-07 Thread Bjoern Schliessmann
S.Mohideen wrote: > There is a dictionary on which I store/read data values. I want to > seperate the send and recv functionality on two different > processes so that the parallel execution becomes fast. What makes you think that'll be faster? Remember: - If you have one CPU, there is no paralle

Re: multithreading concept

2007-02-07 Thread Carl J. Van Arsdall
S.Mohideen wrote: > I would like to add my problem in this thread. > I have a network application in Python which sends and recv using a single > socket. > There is a dictionary on which I store/read data values. I want to seperate > the send and recv functionality on two different processes so t

Re: multithreading concept

2007-02-07 Thread S.Mohideen
Sergei Organov" <[EMAIL PROTECTED]> To: Sent: Wednesday, February 07, 2007 1:03 PM Subject: Re: multithreading concept > "sturlamolden" <[EMAIL PROTECTED]> writes: >> On Feb 7, 6:17 pm, John Nagle <[EMAIL PROTECTED]> wrote: > [...] >> MPI

Re: multithreading concept

2007-02-07 Thread Carl J. Van Arsdall
Paul Boddie wrote: > [snip] > > Take a look at the Python Wiki for information on parallel processing > with Python: > > http://wiki.python.org/moin/ParallelProcessing > What a great resource! That one is book marked for sure. I was wondering if anyone here had any opinions on some of the tec

Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 8:03 pm, Sergei Organov <[EMAIL PROTECTED]> wrote: > I fail to see how threads in general could perform worse than > processes. I do understand that processes are inherently more > safe/secure, but when it comes to speed I really can't imagine why it > could happen that threads perform w

Re: multithreading concept

2007-02-07 Thread Sergei Organov
"sturlamolden" <[EMAIL PROTECTED]> writes: > On Feb 7, 6:17 pm, John Nagle <[EMAIL PROTECTED]> wrote: [...] > MPI does not use threads on SMPs because it performs worse than using > multiple processes. I fail to see how threads in general could perform worse than processes. I do understand that pr

Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 6:17 pm, John Nagle <[EMAIL PROTECTED]> wrote: > Multithread compute-bound programs on multiple CPUs are > how you get heavy number-crunching work done on multiprocessors. In the scientific community, heavy CPU-bound tasks are either parallelized using MPI and/or written in Fortran

Re: multithreading concept

2007-02-07 Thread Steve Holden
John Nagle wrote: > sturlamolden wrote: >> On Feb 7, 2:53 am, "S.Mohideen" <[EMAIL PROTECTED]> >> wrote: >> This has been discussed to death before. Win32 threads and pthreads >> (which is what Python normally uses, depending on the platform) are >> designed to stay idle most of the time. They are

Re: multithreading concept

2007-02-07 Thread John Nagle
sturlamolden wrote: > On Feb 7, 2:53 am, "S.Mohideen" <[EMAIL PROTECTED]> > wrote: > This has been discussed to death before. Win32 threads and pthreads > (which is what Python normally uses, depending on the platform) are > designed to stay idle most of the time. They are therefore not a tool > fo

Re: multithreading concept

2007-02-07 Thread Paul Boddie
On 7 Feb, 02:53, "S.Mohideen" <[EMAIL PROTECTED]> wrote: > > Python is praised about - me too. But at one instance it fails. It fails to > behave as a true multi-threaded application. That means utilizing all the > CPUs parallely in the SMP efficiently stays as a dream for a Python > Programmer. T

Re: multithreading concept

2007-02-07 Thread sturlamolden
On Feb 7, 2:53 am, "S.Mohideen" <[EMAIL PROTECTED]> wrote: > Python is praised about - me too. But at one instance it fails. It fails to > behave as a true multi-threaded application. That means utilizing all the > CPUs parallely in the SMP efficiently stays as a dream for a Python > Programmer.

Re: multithreading concept

2007-02-06 Thread Paddy
On Feb 7, 1:53 am, "S.Mohideen" <[EMAIL PROTECTED]> wrote: > Hi Folks, > > Python is praised about - me too. But at one instance it fails. It fails to > behave as a true multi-threaded application. That means utilizing all the > CPUs parallely in the SMP efficiently stays as a dream for a Python >

Re: multithreading windows and embedding python

2006-07-10 Thread freesteel
freesteel wrote: ... > pThread[ih] = AfxBeginThread(MyThread, mainThreadState, > THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED); ... Here the call to AfxBeginThread is wrong, there is one argument missing, it should be: pThread[ih] = AfxBeginThread(MyThread, mainThreadState, TH

Re: multithreading and shared dictionary

2006-07-08 Thread Aahz
In article <[EMAIL PROTECTED]>, Istvan Albert <[EMAIL PROTECTED]> wrote: >Marc 'BlackJack' Rintsch wrote: >> >> It's not in Jython nor IronPython and maybe not forever in >> CPython. > >Whether or not a feature is present in Jython or IronPython does not >seem relevant, after all these languages em

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote: ... > Alex Martelli wrote: > > Well then, feel free to code under such assumptions (as long as you're > > not working on any project in which I have any say:-) > > Hey, I would *never* write code which depends on such intricate > implementation details! No

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote: > Well then, feel free to code under such assumptions (as long as you're > not working on any project in which I have any say:-) Hey, I would *never* write code which depends on such intricate implementation details! Nonetheless, its good to *know* whats going on inside. As th

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
Istvan Albert <[EMAIL PROTECTED]> wrote: > Marc 'BlackJack' Rintsch wrote: > > > It's not in Jython nor IronPython and maybe not forever in > > CPython. > > Whether or not a feature is present in Jython or IronPython does not > seem relevant, after all these languages emulate Python, one could

Re: multithreading and shared dictionary

2006-07-08 Thread Alex Martelli
K.S.Sreeram <[EMAIL PROTECTED]> wrote: ... > Consider two threads A and B, which are independent except for the fact > that they reside in the same module. > > def thread_A() : > global foo > foo = 1 > > def thread_B() : > global bar > bar = 2 > > These threads create entries

Re: multithreading and shared dictionary

2006-07-08 Thread Istvan Albert
Marc 'BlackJack' Rintsch wrote: > It's not in Jython nor IronPython and maybe not forever in > CPython. Whether or not a feature is present in Jython or IronPython does not seem relevant, after all these languages emulate Python, one could argue that it only means that this emulation is incomplet

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote: > Wrong, alas: each assignment *could* cause the dictionary's internal > structures to be reorganized (rehashed) and impact another assignment > (or even 'get'-access). (been thinking about this further...) Dictionary get/set operations *must* be atomic, because Python makes

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Marc 'BlackJack' Rintsch wrote: >>> Wrong, alas: each assignment *could* cause the dictionary's internal >>> structures to be reorganized (rehashed) and impact another assignment >>> (or even 'get'-access). >> but wont the GIL be locked when the rehash occurs? > > If there is a GIL then maybe yes.

Re: multithreading and shared dictionary

2006-07-08 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, K.S.Sreeram wrote: > Alex Martelli wrote: >> Wrong, alas: each assignment *could* cause the dictionary's internal >> structures to be reorganized (rehashed) and impact another assignment >> (or even 'get'-access). > > but wont the GIL be locked when the rehash occurs? If

Re: multithreading and shared dictionary

2006-07-08 Thread K.S.Sreeram
Alex Martelli wrote: > Wrong, alas: each assignment *could* cause the dictionary's internal > structures to be reorganized (rehashed) and impact another assignment > (or even 'get'-access). but wont the GIL be locked when the rehash occurs? Regards Sreeram signature.asc Description: OpenPGP di

Re: multithreading and shared dictionary

2006-07-08 Thread placid
Alex Martelli wrote: > Istvan Albert <[EMAIL PROTECTED]> wrote: > > > Stéphane Ninin wrote: > > > > > Is a lock required in such a case ? > > > > I believe that assignment is atomic and would not need a lock. > > Wrong, alas: each assignment *could* cause the dictionary's internal > structures to

Re: multithreading and shared dictionary

2006-07-07 Thread Alex Martelli
Istvan Albert <[EMAIL PROTECTED]> wrote: > Stéphane Ninin wrote: > > > Is a lock required in such a case ? > > I believe that assignment is atomic and would not need a lock. Wrong, alas: each assignment *could* cause the dictionary's internal structures to be reorganized (rehashed) and impact a

Re: multithreading and shared dictionary

2006-07-07 Thread Istvan Albert
Stéphane Ninin wrote: > Is a lock required in such a case ? I believe that assignment is atomic and would not need a lock. yet most of the other dictionary use cases are not threadsafe. For example I suspect that you'd get an error if you were iterating through the dictionary while another threa

Re: multithreading and shared dictionary

2006-07-07 Thread placid
Stéphane Ninin wrote: > Hello, > > Probably a stupid question, but I am not a multithreading expert... > > I want to share a dictionary between several threads. > Actually, I will wrap the dictionary in a class > and want to protect the "sensitive accesses" with locks. > > The problem is I am not

Re: Multithreading and Queue

2006-04-25 Thread robert
Jeffrey Barish wrote: > Several methods in Queue.Queue have warnings in their doc strings that they > are not reliable (e.g., qsize). I note that the code in all these methods > is bracketed with lock acquire/release. These locks are intended to > protect the enclosed code from collisions with ot

Re: Multithreading and Queue

2006-04-25 Thread Tim Peters
[Jeffrey Barish] > Several methods in Queue.Queue have warnings in their doc strings that they > are not reliable (e.g., qsize). I note that the code in all these methods > is bracketed with lock acquire/release. These locks are intended to > protect the enclosed code from collisions with other t

Re: Multithreading tkinter question

2004-12-17 Thread Eric Brunel
Oleg Paraschenko wrote: [snip] In my case "Hello" works and "Quit" doesn't (GUI stays frozen). Linux, Python 2.3.3, pygtk-0.6.9. That's not a multithreading issue, but just the way the quit method works. Try: - import time from Tkinter import * root

Re: Multithreading tkinter question

2004-12-16 Thread Oleg Paraschenko
Hello John, > Mark, > > I tried your code snippet with Python 2.3.4. Worked fine. Only problem was > that the program fell off the end and terminated before the second thread > could open the Tkinter window. So I added these lines at the end to make the > main thread wait:- > > from msvcrt import

Re: Multithreading tkinter question

2004-12-16 Thread Mark English
> Date: Thu, 16 Dec 2004 11:59:53 GMT > From: "John Pote" <[EMAIL PROTECTED]> > > "Mark English" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > Is there a safe way to run tkinter in a multithreaded app > where the mainloop runs in a background thread ? > > > I tried your code

Re: Multithreading tkinter question

2004-12-16 Thread John Pote
"Mark English" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Is there a safe way to run tkinter in a multithreaded app where the mainloop runs in a background thread ? Mark, I tried your code snippet with Python 2.3.4. Worked fine. Only problem was that the program fell off the