Re: Please help with Threading

2013-06-02 Thread Jurgens de Bruin
On Saturday, 18 May 2013 10:58:13 UTC+2, Jurgens de Bruin wrote: This is my first script where I want to use the python threading module. I have a large dataset which is a list of dict this can be as much as 200 dictionaries in the list. The final goal is a histogram for each dict 16

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Python threads work fine if the threads either rely on intelligent DLLs for number crunching (instead of doing nested Python loops to process a numeric array you pass it to something like NumPy which releases the GIL

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 07:25, Fábio Santos fabiosantos...@gmail.com wrote: | On 18 May 2013 20:33, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: | Python threads work fine if the threads either rely on intelligent | DLLs for number crunching (instead of doing nested Python loops to | process a

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
Date: Sun, 19 May 2013 13:10:36 +1000 From: c...@zip.com.au To: carlosnepomuc...@outlook.com CC: python-list@python.org Subject: Re: Please help with Threading On 19May2013 03:02, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | Just been

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
Date: Mon, 20 May 2013 17:45:14 +1000 From: c...@zip.com.au To: fabiosantos...@gmail.com Subject: Re: Please help with Threading CC: python-list@python.org; wlfr...@ix.netcom.com On 20May2013 07:25, Fábio Santos fabiosantos...@gmail.com wrote

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
My use case was a tight loop processing an image pixel by pixel, or crunching a CSV file. If it only uses local variables (and probably hold a lock before releasing the GIL) it should be safe, no? My idea is that it's a little bad to have to write C or use multiprocessing just to do simultaneous

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 10:53, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | I just got my hands dirty trying to synchronize Python prints from many threads. | Sometimes they mess up when printing the newlines. | I tried several approaches using threading.Lock and Condition. | None of them worked

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? Fun little hack: def print(*args,print=print,lock=Lock(),**kwargs): with lock:

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
It is pretty cool although it looks like a recursive function at first ;) On 20 May 2013 10:13, Chris Angelico ros...@gmail.com wrote: On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock:

Re: Please help with Threading

2013-05-20 Thread Cameron Simpson
On 20May2013 19:09, Chris Angelico ros...@gmail.com wrote: | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: |_lock = Lock() | |def lprint(*a, **kw): | global _lock | with _lock: |print(*a, **kw) | | and use lprint() everywhere? | | Fun little

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
Date: Mon, 20 May 2013 18:35:20 +1000 From: c...@zip.com.au To: carlosnepomuc...@outlook.com CC: python-list@python.org Subject: Re: Please help with Threading On 20May2013 10:53, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | I just got my

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Mon, May 20, 2013 at 7:54 PM, Cameron Simpson c...@zip.com.au wrote: On 20May2013 19:09, Chris Angelico ros...@gmail.com wrote: | On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: |_lock = Lock() | |def lprint(*a, **kw): | global _lock | with

Re: Please help with Threading

2013-05-20 Thread Ned Batchelder
On 5/20/2013 6:09 AM, Chris Angelico wrote: Referencing a function's own name in a default has to have one of these interpretations: 1) It's a self-reference, which can be used to guarantee recursion even if the name is rebound 2) It references whatever previously held that name before this def

Re: Please help with Threading

2013-05-20 Thread Dave Angel
On 05/20/2013 03:55 AM, Fábio Santos wrote: My use case was a tight loop processing an image pixel by pixel, or crunching a CSV file. If it only uses local variables (and probably hold a lock before releasing the GIL) it should be safe, no? Are you making function calls, using system

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
=On Mon, May 20, 2013 at 8:46 PM, Ned Batchelder n...@nedbatchelder.com wrote: On 5/20/2013 6:09 AM, Chris Angelico wrote: Referencing a function's own name in a default has to have one of these interpretations: 1) It's a self-reference, which can be used to guarantee recursion even if the

Re: Please help with Threading

2013-05-20 Thread Fábio Santos
I didn't know that. On 20 May 2013 12:10, Dave Angel da...@davea.name wrote: Are you making function calls, using system libraries, or creating or deleting any objects? All of these use the GIL because they use common data structures shared among all threads. At the lowest level, creating an

Re: Please help with Threading

2013-05-20 Thread 88888 Dihedral
Chris Angelico於 2013年5月20日星期一UTC+8下午5時09分13秒寫道: On Mon, May 20, 2013 at 6:35 PM, Cameron Simpson c...@zip.com.au wrote: _lock = Lock() def lprint(*a, **kw): global _lock with _lock: print(*a, **kw) and use lprint() everywhere? Fun little

Re: Please help with Threading

2013-05-20 Thread Chris Angelico
On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
to the sys module in the 'Lib' directory? Date: Tue, 21 May 2013 11:50:17 +1000 Subject: Re: Please help with Threading From: ros...@gmail.com To: python-list@python.org On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK

RE: Please help with Threading

2013-05-20 Thread Carlos Nepomuceno
On Tue, May 21, 2013 at 11:44 AM, 8 Dihedral dihedral88...@googlemail.com wrote: OK, if the python interpreter has a global hiden print out buffer of ,say, 2to 16 K bytes, and all string print functions just construct the output string from the format to this string in an efficient low

Re: Please help with Threading

2013-05-20 Thread Steven D'Aprano
On Tue, 21 May 2013 05:53:46 +0300, Carlos Nepomuceno wrote: BTW, why I didn't find the source code to the sys module in the 'Lib' directory? Because sys is a built-in module. It is embedded in the Python interpreter. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Please help with Threading

2013-05-19 Thread Chris Angelico
On Mon, May 20, 2013 at 7:46 AM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Sun, 19 May 2013 10:38:14 +1000, Chris Angelico ros...@gmail.com declaimed the following in gmane.comp.python.general: With interpreted code eg in CPython, it's easy to implement preemption in the interpreter. I

Re: Please help with Threading

2013-05-19 Thread Dave Angel
On 05/19/2013 05:46 PM, Dennis Lee Bieber wrote: On Sun, 19 May 2013 10:38:14 +1000, Chris Angelico ros...@gmail.com declaimed the following in gmane.comp.python.general: On Sun, May 19, 2013 at 10:02 AM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: I didn't know Python threads

Please help with Threading

2013-05-18 Thread Jurgens de Bruin
This is my first script where I want to use the python threading module. I have a large dataset which is a list of dict this can be as much as 200 dictionaries in the list. The final goal is a histogram for each dict 16 histograms on a page ( 4x4 ) - this already works. What I currently do is

Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote: This is my first script where I want to use the python threading module. I have a large dataset which is a list of dict this can be as much as 200 dictionaries in the list. The final goal is a histogram for each dict 16 histograms on a page ( 4x4 ) - this already

Re: Please help with Threading

2013-05-18 Thread Jurgens de Bruin
I will post code - the entire scripts is 1000 lines of code - can I post the threading functions only? -- http://mail.python.org/mailman/listinfo/python-list

Re: Please help with Threading

2013-05-18 Thread Peter Otten
Jurgens de Bruin wrote: I will post code - the entire scripts is 1000 lines of code - can I post the threading functions only? Try to condense it to the relevant parts, but make sure that it can be run by us. As a general note, when you add new stuff to an existing longish script it is

Re: Please help with Threading

2013-05-18 Thread Dave Angel
On 05/18/2013 04:58 AM, Jurgens de Bruin wrote: This is my first script where I want to use the python threading module. I have a large dataset which is a list of dict this can be as much as 200 dictionaries in the list. The final goal is a histogram for each dict 16 histograms on a page (

RE: Please help with Threading

2013-05-18 Thread Carlos Nepomuceno
To: python-list@python.org From: wlfr...@ix.netcom.com Subject: Re: Please help with Threading Date: Sat, 18 May 2013 15:28:56 -0400 On Sat, 18 May 2013 01:58:13 -0700 (PDT), Jurgens de Bruin debrui...@gmail.com declaimed the following

Re: Please help with Threading

2013-05-18 Thread Chris Angelico
On Sun, May 19, 2013 at 10:02 AM, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: I didn't know Python threads aren't preemptive. Seems to be something really old considering the state of the art on parallel execution on multi-cores. What's the catch on making Python threads preemptive?

Re: Please help with Threading

2013-05-18 Thread Cameron Simpson
On 19May2013 03:02, Carlos Nepomuceno carlosnepomuc...@outlook.com wrote: | Just been told that GIL doesn't make things slower, but as I | didn't know that such a thing even existed I went out looking for | more info and found that document: | http://www.dabeaz.com/python/UnderstandingGIL.pdf | |