Re: CPython on the Web

2011-01-03 Thread azakai
On Jan 3, 10:11 pm, John Nagle  wrote:
> On 1/1/2011 11:26 PM, azakai wrote:
>
> > Hello, I hope this will be interesting to people here: CPython running
> > on the web,
>
> >http://syntensity.com/static/python.html
>
> > That isn't a new implementation of Python, but rather CPython 2.7.1,
> > compiled from C to JavaScript using Emscripten and LLVM. For more
> > details on the conversion process, seehttp://emscripten.org
>
>     It's a cute hack, but it's about 1000 times slower than CPython.
>
> Try
>
> def cnt(n) :
>      j = 0
>      for i in xrange(n) :
>          j = j + 1
>      return(j)
>
> print(cnt(100))
>
> with this.  It will take 30 seconds or so to count to a million.
>
>                                         John Nagle

Yes, as I said, "the code isn't optimized (so
don't expect good performance)" :)

It can get much faster with more work.

- azakai
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Jean-Paul Calderone
On Jan 3, 6:17 pm, Adam Skutt  wrote:
> On Jan 3, 5:24 pm, Jean-Paul Calderone 
> wrote:
>
> > Of course.  The whole point here is not about threads vs processes.
> > It's about shared memory concurrency vs non-shared memory
> > concurrency.  You can implement both with threads and both with
> > processes, but threads are geared towards shared memory and processes
> > are geared towards non-shared memory.  So what most people mean by
> > "use processes" is "don't use shared memory".
>
> This is entirely my presumption, but I think if the OP were keenly
> aware of the differences between thread and processes, it's pretty
> likely he wouldn't have asked his question in the first place.
>

Fair enough. :)

> Also, I've written lots and lots of "use processes" code on multiple
> platforms, and much of it has used some sort of shared memory
> construct.  It's actually pretty common, especially in code bases with
> a lot of history.  Not all the world is Apache.
>

Hee hee, Apache. :)

> Adam

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread John Nagle

On 1/1/2011 11:26 PM, azakai wrote:

Hello, I hope this will be interesting to people here: CPython running
on the web,

http://syntensity.com/static/python.html

That isn't a new implementation of Python, but rather CPython 2.7.1,
compiled from C to JavaScript using Emscripten and LLVM. For more
details on the conversion process, see http://emscripten.org


   It's a cute hack, but it's about 1000 times slower than CPython.

Try

def cnt(n) :
j = 0
for i in xrange(n) :
j = j + 1
return(j)

print(cnt(100))

with this.  It will take 30 seconds or so to count to a million.

John Nagle
--
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-03 Thread Paul Rubin
"Octavian Rasnita"  writes:
> If I want to create a dictionary from a list...
> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

dict(l[i:i+2] for i in xrange(0,len(l),2))

seems simplest to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread MrJean1
FYI,

The example

  http://syntensity.com/static/python.html

works fine in Safari 4.1.3 on MacOS X Tiger (10.4.11).

/Jean


On Jan 3, 5:59 pm, azakai  wrote:
> On Jan 3, 12:23 pm, Gerry Reno  wrote:
>
>
>
>
>
> > On 01/03/2011 03:10 PM, azakai wrote:
>
> > > On Jan 2, 5:55 pm, Gerry Reno  wrote:
>
> > >> I tried printing sys.path and here is the output:
>
> > >> ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/',
> > >> '/usr/local/lib/python2.7/plat-linux2',
> > >> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> > >> '/usr/local/lib/lib-dynload']
>
> > >> Now, those paths must be on your machine because they are not on my
> > >> client machine.  But the interpreter is now running on MY machine.  Well
> > >> in a sandbox really.  So how is that going to work?
>
> > > Yeah, those are the paths on the machine where the binary was compiled
> > > (so, they are the standard paths on ubuntu).
>
> > > Anyhow the filesystem can't (and shouldn't) be accessed from inside a
> > > browser page.
>
> > Well, the local filesystem could be accessible with the user's
> > permission and this should be an option.
>
> Hmm, I think this might be possible with the HTML5 File API. Would
> definitely be useful here.
>
> - azakai

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-03 Thread DevPlayer
An adaptation to Hrvoje Niksic's recipe

Use a dictionary comprehention instead of a list comprehension or
function call:

lyst = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']

it = iter( lyst )
dyct = {i:it.next() for i in it}  # I'm using {} and not [] for those
with tiny fonts.

#print dyct
{8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}

Of course check for an "even" number of elements to the original list
to avoid exceptions or dropping the last element on traps.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread MrJean1
FireFox 3.6.13 on MacOS X Tiger (10.4.11) fails:

  Error: too much recursion
  Error: Modules is not defined
  Source File: http://synthensity.com/static/python.html

/Jean

On Jan 2, 11:26 pm, Wolfgang Strobl  wrote:
> azakai :
>
> >On Jan 2, 4:58 pm, pyt...@bdurham.com wrote:
> >> Azakai/Gerry,
>
> >> > Errors when using Firefox 3.6.3:
>
> >> I'm running Firefox 3.6.1.3 and the interpreter is running fine.
>
> I guess that meant FIrefox 3.6.13 (without the last dot), the current
> stable version.
>
> I'm using Firefox 3.6.13 (german) on Windowx XP (32bit, german) here,
> and the interpreter is running fine, too.  Same for Chrome 8.0.552.224.
>
> --
> Wir danken f r die Beachtung aller Sicherheitsbestimmungen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python comparison matrix

2011-01-03 Thread Tomasz Rola
On Mon, 3 Jan 2011, Alex Willmer wrote:

> I've created a spreadsheet that compares the built ins, features and 
> modules of the CPython releases so far. For instance it shows: 
[...]
> I gathered the data from the documentation at python.org. It's work in 
> progress so there are plenty of rough edges and holes, but I'd like to 
> get your opinions, feedback and suggestions. 
> - Would you find such a document useful? 

Yes, definitely.  Great idea, thanks for doing this.

> - What format(s) would be most useful to you (e.g. spreadsheet, pdf, web 
> page(s), database, wall chart, desktop background)?

I would vote for html/web pages with pdf as an option (i.e. a link), if 
you find it easy enough to make. This probably means you would like to 
have the source in a form that allows generation of both pages and pdf 
without much trouble. In this case, it seems there are more than few 
options to choose from.

Perhaps in a form of Python code doing the job, with data in hashtables? 
That would be so Pythonish :-).

> - Are there other aspects/pages that you'd like to see included?
> - Do you know of source(s) for which versions of CPython supported which 
> operating systems (e.g. the first and last Python release that works on 
> Windows 98 or Mac OS 9)? The best I've found so far is PEP 11

Nothing comes to my head ATM.

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:tomasz_r...@bigfoot.com **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String building using join

2011-01-03 Thread Kushal Kumaran
On Mon, Jan 3, 2011 at 3:07 AM, gervaz  wrote:
> On 2 Gen, 19:14, Emile van Sebille  wrote:
>> 
>>
>> class Test:
>>       def __init__(self, v1, v2):
>>           self.v1 = v1
>>           self.v2 = v2
>>
>> t1 = Test("hello", None)
>> t2 = Test(None, "ciao")
>> t3 = Test("salut", "hallo")
>> t = [t1, t2, t3]
>>
>> "\n".join([y for x in t for y in [x.v1,x.v2] if y])
>>
>>
>>
> 
>
> Thanks Emile, despite that now the solution runs in quadratic time I
> guess. I could also provide a __str__(self) representation, but in my
> real code I don't have access to the class. Also using str() on an
> empty object (i.e. None), the representation is 'None'.
>

Since no one else has mentioned it, I'll just point out that Emile's
solution does not run in quadratic time.  It has the same number of
operations as the originally posted code.

That str(None) results in "None" is not a problem because of the "if
y" test in the list comprehension.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multiple instances and wrong parental links

2011-01-03 Thread DevPlayer

Mere are my ramblings of a novice (bad) Hobbyst programmer.

You mentioned that your having a hard time coming up with a solution
to your complex problem. Complex means you are doing lots of different
things to different things all over the place where timing is an
issue.

First it seems you are trying to simplify your problem by creating a
generic class you might call Element which is held in an ElementList
class. Right?

Or is it you would like you to create a new class for each unique
element? If this is the case it would be because each unique element -
behaves- differently. Is this the case? Or do all XML elements
basically behave the same? If they behave the same you're confusing
your design. A class  represents a unique behavior. Remember instances
can have unique attributes like "code" or "title". But I'm digressing.

For example in your other discussion you posted at:
https://groups.google.com/forum/#!topic/comp.lang.python/K9PinAbuCJk/discussion
you say:

So, an element like:


Writers of the Future


Or is the element structure?:


"some value"


Or is it like this?


value


Or like this?


value
value
...


Or this, typical XML?


value
value
...

value
value
...




And is  nested or only one "sub" deep?

Ask yourself why do you need to have a different class for each unique
element type? Or in other words, why do you need a new class for each
XML tag pair?

If your elements are nested to some unknown depth, perhaps broaden
your idea of your ElementList into an ElementTree.

Take a look at the section "Basic Usage" midway down at url:
http://effbot.org/zone/element-index.htm


Or change you Market Class stucture(in your other discussion) to make
it more dimensional by adding a tag attribute which would
mark it as if it were a certain "class".

class ElementNode(objec):
def__init__(self, parent, elem)
self.parent = parent# another elementNode object or None
self.elem = elem # entire text block or just do offsets
(i.e. file line numbers)
self.tag = self.get_tag(elem)   # market  tag==class
self.token = self.get_token(self) # "code" or whatever if
variable
self.sub_elems= self.get_subs(elem) # recursive ElementNodes;
return a list or dict

self.root = self.get_root(parent)   # optional but handy
# I like to use the root as the XML source; sometimes an
XML file
self.next = None   # because I love double link lists
# probably useful for that ObjectListView wxPython widget


If in your case each Element does behave differently (ie has unique
methods) then perhaps you should be looking at some other solution.
Perhaps class factories or meta classes. I can't help you there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread azakai
On Jan 3, 12:23 pm, Gerry Reno  wrote:
> On 01/03/2011 03:10 PM, azakai wrote:
>
>
>
>
>
>
>
>
>
> > On Jan 2, 5:55 pm, Gerry Reno  wrote:
>
> >> I tried printing sys.path and here is the output:
>
> >> ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/',
> >> '/usr/local/lib/python2.7/plat-linux2',
> >> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> >> '/usr/local/lib/lib-dynload']
>
> >> Now, those paths must be on your machine because they are not on my
> >> client machine.  But the interpreter is now running on MY machine.  Well
> >> in a sandbox really.  So how is that going to work?
>
> > Yeah, those are the paths on the machine where the binary was compiled
> > (so, they are the standard paths on ubuntu).
>
> > Anyhow the filesystem can't (and shouldn't) be accessed from inside a
> > browser page.
>
> Well, the local filesystem could be accessible with the user's
> permission and this should be an option.
>

Hmm, I think this might be possible with the HTML5 File API. Would
definitely be useful here.

- azakai
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python comparison matrix

2011-01-03 Thread Alex Willmer
Thank you Antoine, I've fixed those errors. Going by the docs, I have VMSError 
down as first introduced in Python 2.5.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python comparison matrix

2011-01-03 Thread Alex Willmer
On Tuesday, January 4, 2011 12:54:24 AM UTC, Malcolm wrote:
> Alex,
> 
> I think this type of documentation is incredibly useful!

Thank you.

> Is there some type of key which explains symbols like !, *, f, etc?

There is a key, it's the second tab from the end, '!' wasn't documented and I 
forgot why I marked bytes() thusly, so I've removed it.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread azakai
On Jan 3, 12:13 pm, de...@web.de (Diez B. Roggisch) wrote:
> A fun hack. Have you bothered to compare it to the PyPy javascript
> backend - perfomance-wise, that is?
>

Gerry already gave a complete and accurate answer to the status of
this project in comparison to PyPy and pyjamas. Regarding performance,
this hack is not currently fast, primarily because the code is not
optimized yet.

But through a combination of optimizations on the side of Emscripten
(getting all LLVM optimizations to work when compiling to JS) and on
the side of the browsers (optimizing accesses on typed arrays in JS,
etc.), then I hope the code will eventually run quite fast, even
comparably to C.

- azakai
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python comparison matrix

2011-01-03 Thread python
Alex,

I think this type of documentation is incredibly useful!

Is there some type of key which explains symbols like !, *, f, etc?

Thanks for sharing this work with the community.

Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python comparison matrix

2011-01-03 Thread Antoine Pitrou
On Mon, 3 Jan 2011 16:17:00 -0800 (PST)
Alex Willmer  wrote:
> I've created a spreadsheet that compares the built ins, features and modules 
> of the CPython releases so far. For instance it shows: 

A couple of errors:
- BufferError is also in 3.x
- IndentationError is also in 3.x
- object is also in 3.x
- NotImplemented is not an exception type, it's a built-in singleton
  like None
- you forgot VMSError (only on VMS) :-)

Regards

Antoine.


-- 
http://mail.python.org/mailman/listinfo/python-list


Python comparison matrix

2011-01-03 Thread Alex Willmer
I've created a spreadsheet that compares the built ins, features and modules of 
the CPython releases so far. For instance it shows: 
- basestring was first introduced at version 2.3 then removed in version 3.0
- List comprehensions (PEP 202) were introduced at version 2.0.
- apply() was a built in throughout the 1.x and 2.x series, but was deprecated 
in from 2.3 and removed in 3.0
- Generator functions were first introduced in 2.2 with __future__ import, from 
2.3 they were fully supported

https://spreadsheets.google.com/pub?key=0At5kubLl6ri7dHU2OEJFWkJ1SE16NUNvaGg2UFBxMUE

The current version covers CPython 1.5 - 3.2 on these aspects:
- Built in types and functions
- Keywords
- Modules
- Interpreter switches and environment variables
- Platforms, including shipped Python version(s) for major Linux distributions
- Features/PEPs (incomplete)

I gathered the data from the documentation at python.org. It's work in progress 
so there are plenty of rough edges and holes, but I'd like to get your 
opinions, feedback and suggestions.
- Would you find such a document useful? 
- What format(s) would be most useful to you (e.g. spreadsheet, pdf, web 
page(s), database, wall chart, desktop background)?
- Are there other aspects/pages that you'd like to see included?
- Do you know of source(s) for which versions of CPython supported which 
operating systems (e.g. the first and last Python release that works on Windows 
98 or Mac OS 9)? The best I've found so far is PEP 11

Regards and thanks, Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread astar
On Jan 2, 4:58 pm, pyt...@bdurham.com wrote:
> Azakai/Gerry,
>
> > Errors when using Firefox 3.6.3:
>


firefox 3.6.13 openbsd i386 4.8 -current
error console has some errors:

editor not defined
module not define
too much recursion

nothing interested happened on the web page, but wonderful project
anyway

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SUNLisp 2: Josh vs. Kenny Flamewars Galore!!

2011-01-03 Thread Thomas 'PointedEars' Lahn
kenny crossposted bullshit over 5 newsgroups again:

> […]

JFTR: *PLONK*
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Adam Skutt
On Jan 3, 5:24 pm, Jean-Paul Calderone 
wrote:
> Of course.  The whole point here is not about threads vs processes.
> It's about shared memory concurrency vs non-shared memory
> concurrency.  You can implement both with threads and both with
> processes, but threads are geared towards shared memory and processes
> are geared towards non-shared memory.  So what most people mean by
> "use processes" is "don't use shared memory".
>

This is entirely my presumption, but I think if the OP were keenly
aware of the differences between thread and processes, it's pretty
likely he wouldn't have asked his question in the first place.

Also, I've written lots and lots of "use processes" code on multiple
platforms, and much of it has used some sort of shared memory
construct.  It's actually pretty common, especially in code bases with
a lot of history.  Not all the world is Apache.

Adam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread Gerry Reno
On 01/03/2011 05:55 PM, Diez B. Roggisch wrote:
> Gerry Reno  writes:
>
>   
>> On 01/03/2011 03:13 PM, Diez B. Roggisch wrote:
>> 
>>> A fun hack. Have you bothered to compare it to the PyPy javascript
>>> backend - perfomance-wise, that is?
>>>
>>> Diez
>>>   
>>>   
>> I don't think that exists anymore.  Didn't that get removed from PyPy
>> about 2 years ago?
>> 
> Ah, didn't know that. I was under the impression pyjamas was done with
> it. Apparently, that's wrong:
>
>  http://pyjs.org/
>
> But then I re-phrase my question: how does this relate to pyjamas/pyjs?
>
> Diez
>   

>From what I've seen so far:

Pyjamas is taking your python code and converting it into javascript so
that your python code (converted to javascript) can run in a browser.

CPotW is taking the whole python interpreter and converting the
interpreter into javascript so that the python interpreter runs in the
browser.  Your python code remains as python code.


Regards,
Gerry

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Adam Skutt
On Jan 3, 5:05 pm, gervaz  wrote:
> Regarding the case pointed out by Adam I think the best way to
> deal with it is to create a critical section so that the shared memory
> will be updated in an atomic fashion.

Ok, so if the OS kills the process between taking the lock and
releasing it, what are you going to do?  Handled naively, you can end
up in a deadlock situation[1]. If a process has locked a semaphore and
then terminates, the semaphore retains its current value: all other
processes waiting on the semaphore will still be waiting, and any new
processes that access the semaphore will wait as well.  In short, if a
process holding a semaphore dies, you have to manually unlock it.

For signals that the process intends to handle, you can always disable
them before taking the lock and reenable them after releasing it.  Or,
you can install signal handlers in each process that ensure everything
is properly cleaned up when the signal is delivered.  Which solution
is right depends on what you're doing.

For signals you don't intend to handle (SIGSEGV) or cannot handle
(SIGKILL) there's not much you can do.  It's potentially dangerous to
continue on after a child has received such a signal, so the right
solution may be to literally do nothing and let the deadlock occur.
If you must do cleanup, it must be done carefully.  The key thing to
understand is that the problems with killing threads haven't gone
away: delivering the "please die" message isn't the hard part; it's
safely cleaning up the thread in such a way it doesn't break the rest
of the application!  This problem still exists if you replace threads
with processes (assuming you're using shared memory).

As such, the better thing to do, if possible, is to avoid shared
memory and use constructs like pipes and sockets for I/O.  They have
much better defined failure semantics, and do allow you a modicum of
fault isolation.  At the very least, graceful shutdown is much easier.

HTH,
Adam

[1] For SIGINT from the terminal, the "right thing" /might/ happen.
Strong emphasis on the might.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Diez B. Roggisch
gervaz  writes:

> On 3 Gen, 22:17, Adam Skutt  wrote:
>> On Jan 3, 4:06 pm, Jean-Paul Calderone 
>> wrote:
>>
>>
>>
>> > > Multiple processes, ok, but then regarding processes' interruption
>> > > there will be the same problems pointed out by using threads?
>>
>> > No.  Processes can be terminated easily on all major platforms.  See
>> > `os.kill`.
>>
>> Yes, but that's not the whole story, now is it?  It's certainly much
>> more reliable and easier to kill a process.  It's not any easier to do
>> it and retain defined behavior, depending on exactly what you're
>> doing.  For example, if you kill it while it's in the middle of
>> updating shared memory, you can potentially incur undefined behavior
>> on the part of any process that can also access shared memory.
>>
>> In short, taking a program that uses threads and shared state and
>> simply replacing the threads with processes will likely not gain you a
>> thing.  It entirely depends on what those threads are doing and how
>> they do it.
>>
>> Adam
>
> As per the py3.1 documentation, os.kill is only available in the Unix
> os. Regarding the case pointed out by Adam I think the best way to
> deal with it is to create a critical section so that the shared memory
> will be updated in an atomic fashion. Btw it would be useful to take a
> look at some actual code/documentation in order to understand how
> others dealt with the problem...

There is the multiprocessing module. It's a good start, and works
cross-platform.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread Diez B. Roggisch
Gerry Reno  writes:

> On 01/03/2011 03:13 PM, Diez B. Roggisch wrote:
>>
>> A fun hack. Have you bothered to compare it to the PyPy javascript
>> backend - perfomance-wise, that is?
>>
>> Diez
>>   
>
> I don't think that exists anymore.  Didn't that get removed from PyPy
> about 2 years ago?

Ah, didn't know that. I was under the impression pyjamas was done with
it. Apparently, that's wrong:

 http://pyjs.org/

But then I re-phrase my question: how does this relate to pyjamas/pyjs?

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


SUNLisp 2: Josh vs. Kenny Flamewars Galore!!

2011-01-03 Thread kenny
All they agree on is Common Lisp! Come join the Yobbos of MCNA at the
Frog & Toad for booze, vino, and great food and knock down drag out
debates galore on everything from Cells to Lisp IDEs:

When: Tomorrow Tuesday, at 7pm
Where: http://www.thefrogandtoadpub.com/

HK

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Jean-Paul Calderone
On Jan 3, 4:17 pm, Adam Skutt  wrote:
> On Jan 3, 4:06 pm, Jean-Paul Calderone 
> wrote:
>
>
>
> > > Multiple processes, ok, but then regarding processes' interruption
> > > there will be the same problems pointed out by using threads?
>
> > No.  Processes can be terminated easily on all major platforms.  See
> > `os.kill`.
>
> Yes, but that's not the whole story, now is it?  It's certainly much
> more reliable and easier to kill a process.  It's not any easier to do
> it and retain defined behavior, depending on exactly what you're
> doing.  For example, if you kill it while it's in the middle of
> updating shared memory, you can potentially incur undefined behavior
> on the part of any process that can also access shared memory.

Then don't use shared memory.

>
> In short, taking a program that uses threads and shared state and
> simply replacing the threads with processes will likely not gain you a
> thing.  It entirely depends on what those threads are doing and how
> they do it.
>

Of course.  The whole point here is not about threads vs processes.
It's about shared memory concurrency vs non-shared memory
concurrency.  You can implement both with threads and both with
processes, but threads are geared towards shared memory and processes
are geared towards non-shared memory.  So what most people mean by
"use processes" is "don't use shared memory".

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 22:17, Adam Skutt  wrote:
> On Jan 3, 4:06 pm, Jean-Paul Calderone 
> wrote:
>
>
>
> > > Multiple processes, ok, but then regarding processes' interruption
> > > there will be the same problems pointed out by using threads?
>
> > No.  Processes can be terminated easily on all major platforms.  See
> > `os.kill`.
>
> Yes, but that's not the whole story, now is it?  It's certainly much
> more reliable and easier to kill a process.  It's not any easier to do
> it and retain defined behavior, depending on exactly what you're
> doing.  For example, if you kill it while it's in the middle of
> updating shared memory, you can potentially incur undefined behavior
> on the part of any process that can also access shared memory.
>
> In short, taking a program that uses threads and shared state and
> simply replacing the threads with processes will likely not gain you a
> thing.  It entirely depends on what those threads are doing and how
> they do it.
>
> Adam

As per the py3.1 documentation, os.kill is only available in the Unix
os. Regarding the case pointed out by Adam I think the best way to
deal with it is to create a critical section so that the shared memory
will be updated in an atomic fashion. Btw it would be useful to take a
look at some actual code/documentation in order to understand how
others dealt with the problem...

Ciao,

Mattia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread Gerry Reno
On 01/03/2011 03:13 PM, Diez B. Roggisch wrote:
>
> A fun hack. Have you bothered to compare it to the PyPy javascript
> backend - perfomance-wise, that is?
>
> Diez
>   

I don't think that exists anymore.  Didn't that get removed from PyPy
about 2 years ago?


Regards,
Gerry

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interesting bug

2011-01-03 Thread John Machin
On Jan 2, 12:22 am, Daniel Fetchinson 
wrote:

> An AI bot is playing a trick on us.

Yes, it appears that the mystery is solved: Mark V. Shaney is alive
and well and living in Bangalore :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread Gerry Reno
On 01/03/2011 03:10 PM, azakai wrote:
> On Jan 2, 5:55 pm, Gerry Reno  wrote:
>   
>> I tried printing sys.path and here is the output:
>>
>> ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/',
>> '/usr/local/lib/python2.7/plat-linux2',
>> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
>> '/usr/local/lib/lib-dynload']
>>
>> Now, those paths must be on your machine because they are not on my
>> client machine.  But the interpreter is now running on MY machine.  Well
>> in a sandbox really.  So how is that going to work?
>>
>> 
> Yeah, those are the paths on the machine where the binary was compiled
> (so, they are the standard paths on ubuntu).
>
> Anyhow the filesystem can't (and shouldn't) be accessed from inside a
> browser page. 

Well, the local filesystem could be accessible with the user's
permission and this should be an option.


Regards,
Gerry

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Adam Skutt
On Jan 3, 4:06 pm, Jean-Paul Calderone 
wrote:
>
> > Multiple processes, ok, but then regarding processes' interruption
> > there will be the same problems pointed out by using threads?
>
> No.  Processes can be terminated easily on all major platforms.  See
> `os.kill`.
>

Yes, but that's not the whole story, now is it?  It's certainly much
more reliable and easier to kill a process.  It's not any easier to do
it and retain defined behavior, depending on exactly what you're
doing.  For example, if you kill it while it's in the middle of
updating shared memory, you can potentially incur undefined behavior
on the part of any process that can also access shared memory.

In short, taking a program that uses threads and shared state and
simply replacing the threads with processes will likely not gain you a
thing.  It entirely depends on what those threads are doing and how
they do it.

Adam
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Jean-Paul Calderone
On Jan 3, 3:22 pm, gervaz  wrote:
> On 3 Gen, 17:47, de...@web.de (Diez B. Roggisch) wrote:
>
>
>
> > gervaz  writes:
> > > On 31 Dic 2010, 23:25, Alice Bevan–McGregor 
> > > wrote:
> > >> On 2010-12-31 10:28:26 -0800, John Nagle said:
>
> > >> > Even worse, sending control-C to a multi-thread program
> > >> > is unreliable in CPython.  See "http://blip.tv/file/2232410";
> > >> > for why.  It's painful.
>
> > >> AFIK, that has been resolved in Python 3.2 with the introduction of an
> > >> intelligent thread scheduler as part of the GIL release/acquire process.
>
> > >>         - Alice.
>
> > > Ok, but then suppose I have multiple long running threads that I want
> > > to delete/suspend because they are tooking too much time, which
> > > solution do you propose?
>
> > If possible, use multiple processes instead.
>
> > Diez- Nascondi testo citato
>
> > - Mostra testo citato -
>
> Multiple processes, ok, but then regarding processes' interruption
> there will be the same problems pointed out by using threads?
>

No.  Processes can be terminated easily on all major platforms.  See
`os.kill`.

Jean-Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread gervaz
On 3 Gen, 17:47, de...@web.de (Diez B. Roggisch) wrote:
> gervaz  writes:
> > On 31 Dic 2010, 23:25, Alice Bevan–McGregor 
> > wrote:
> >> On 2010-12-31 10:28:26 -0800, John Nagle said:
>
> >> > Even worse, sending control-C to a multi-thread program
> >> > is unreliable in CPython.  See "http://blip.tv/file/2232410";
> >> > for why.  It's painful.
>
> >> AFIK, that has been resolved in Python 3.2 with the introduction of an
> >> intelligent thread scheduler as part of the GIL release/acquire process.
>
> >>         - Alice.
>
> > Ok, but then suppose I have multiple long running threads that I want
> > to delete/suspend because they are tooking too much time, which
> > solution do you propose?
>
> If possible, use multiple processes instead.
>
> Diez- Nascondi testo citato
>
> - Mostra testo citato -

Multiple processes, ok, but then regarding processes' interruption
there will be the same problems pointed out by using threads?

Mattia
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread Diez B. Roggisch
azakai  writes:

> Hello, I hope this will be interesting to people here: CPython running
> on the web,
>
> http://syntensity.com/static/python.html
>
> That isn't a new implementation of Python, but rather CPython 2.7.1,
> compiled from C to JavaScript using Emscripten and LLVM. For more
> details on the conversion process, see http://emscripten.org

A fun hack. Have you bothered to compare it to the PyPy javascript
backend - perfomance-wise, that is?

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPython on the Web

2011-01-03 Thread azakai
On Jan 2, 5:55 pm, Gerry Reno  wrote:
> I tried printing sys.path and here is the output:
>
> ['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7/',
> '/usr/local/lib/python2.7/plat-linux2',
> '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old',
> '/usr/local/lib/lib-dynload']
>
> Now, those paths must be on your machine because they are not on my
> client machine.  But the interpreter is now running on MY machine.  Well
> in a sandbox really.  So how is that going to work?
>

Yeah, those are the paths on the machine where the binary was compiled
(so, they are the standard paths on ubuntu).

Anyhow the filesystem can't (and shouldn't) be accessed from inside a
browser page. I think we will implement a minimal virtual filesystem
here, just enough for stuff to work. The actual implementation would
use HTML5 features like local storage etc.

- azakai
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Interrput a thread

2011-01-03 Thread Diez B. Roggisch
gervaz  writes:

> On 31 Dic 2010, 23:25, Alice Bevan–McGregor 
> wrote:
>> On 2010-12-31 10:28:26 -0800, John Nagle said:
>>
>> > Even worse, sending control-C to a multi-thread program
>> > is unreliable in CPython.  See "http://blip.tv/file/2232410";
>> > for why.  It's painful.
>>
>> AFIK, that has been resolved in Python 3.2 with the introduction of an
>> intelligent thread scheduler as part of the GIL release/acquire process.
>>
>>         - Alice.
>
> Ok, but then suppose I have multiple long running threads that I want
> to delete/suspend because they are tooking too much time, which
> solution do you propose?

If possible, use multiple processes instead.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there anyway to run JavaScript in python?

2011-01-03 Thread Diez B. Roggisch
crow  writes:

> Hi, I'm writing a test tool to simulate Web browser. Is there anyway
> to run JavaScript in python? Thanks in advance.

Not really. Yes, you can invoke spidermonkey. But the crucial point
about running JS is not executing JS, it's about having the *DOM* of the
browser available. Which spidermonkey obviously hasn't.

So, I recommend using Selenium. 

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String building using join

2011-01-03 Thread Alexander Gattin
Hello,

On Sun, Jan 02, 2011 at 10:11:50AM -0800, Alex
Willmer wrote:
> def prg3(l):
> return '\n'.join([str(x) for x in l if x])

just one fix (one fix one fix one fix):
return '\n'.join([str(x) for x in l if x is not None])

-- 
With best regards,
xrgtn
-- 
http://mail.python.org/mailman/listinfo/python-list


Arisingsoft provides the Norton antivirus all in one security suite.

2011-01-03 Thread mani ma
hai,

Uses : The package includes a personal firewall, phishing protection
and the ability to detect and remove malware.
Norton 360 is compatible with 32-bit editions of Windows XP and 32-bit
or 64-bit editions of Windows Vista.Windows 7 support has been added.
Reviews cited Norton 360's low resource usage, relative to Norton
Internet Security 2007, and phishing protection.

 
http://www.arisingsoft.com/2010_11_14_archive.html
 http://www.arisingsoft.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list 2 dict?

2011-01-03 Thread Glazner
On Jan 2, 3:18 pm, "Octavian Rasnita"  wrote:
> Hi,
>
> If I want to create a dictionary from a list, is there a better way than the 
> long line below?
>
> l = [1, 2, 3, 4, 5, 6, 7, 'a', 8, 'b']
>
> d = dict(zip([l[x] for x in range(len(l)) if x %2 == 0], [l[x] for x in 
> range(len(l)) if x %2 == 1]))
>
> print(d)
>
> {8: 'b', 1: 2, 3: 4, 5: 6, 7: 'a'}
>
> Thanks.
>
> Octavian

this is efficient

l = [1,2,3,4,5,6]
>>> dict(izip(islice(l,0,len(l),2),islice(l,1,len(l),2)))
{1: 2, 3: 4, 5: 6}
-- 
http://mail.python.org/mailman/listinfo/python-list


A quesstion with matplotlib

2011-01-03 Thread 余亮罡
Dear all,
I have a quesstion about change the width of the ylabel.You know the width 
of the ylabel is relaete to the x axi,how can i change the width of the ylabel 
not depend on the width of the x-axis?
Thank you!
 George




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: The good, the bad, and the ugly!

2011-01-03 Thread Octavian Rasnita
From: "Hank Fay" 
Subject: Re: Tkinter: The good, the bad, and the ugly!

> That (the desktop app issue) was the big game-change for me.  It looks like a 
> desktop app, it acts like a desktop app, and our enterprise customers would 
> be delighted to a) have no installs to do for fat clients; or b) not have to 
> run a TS or Citrix farm. 
> 


It looks like a desktop app, but it doesn't fully act like a desktop app.

Not all the computer users are using a mouse and not all of them can see, but 
the good desktop apps are very accessible for those users who can't do those 
things.

Octavian


-- 
http://mail.python.org/mailman/listinfo/python-list