.pyc keeps running and never stops

2008-11-07 Thread Shao
Dear All,

I am using Python 2.5 and used py_compile to produce a .pyc file.  The
script runs well.  However, the .pyc keeps running and never stops.
Advices will be deeply appreciated.

Regards.

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


Looking for a nitty-gritty Python Ajax middleware script to fire off a number of processors

2008-11-07 Thread Shao
Dear All,

I am looking for a nitty-gritty Python Ajax script to fire off a
number of processing programmes, periodically checking their
operations, sending messages back to an HTML div form by sending back
the links of generated data files, to be downloaded by end users. I am
using .NET IIS 6.0 and Windows Server.

Regards.

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


cunfused why gevent block redis' socket request?

2012-12-28 Thread Tony Shao
GOAL:spawn a few greenlet worker deal with the data pop from redis (pop from 
redis and then put into queue)

RUNNING ENV: ubuntu 12.04
PYTHON VER: 2.7
GEVENT VER: 1.0 RC2
REDIS VER:2.6.5
REDIS-PY VER:2.7.1

from gevent import monkey; monkey.patch_all()
import gevent
from gevent.pool import Group
from gevent.queue import JoinableQueue
import redis

tasks = JoinableQueue()
task_group = Group()

def crawler():
while True:
if not tasks.empty():
print tasks.get()
gevent.sleep()

task_group.spawn(crawler)
redis_client = redis.Redis()
data = redis_client.lpop('test') #<--Block here
tasks.put(data)


Try to pop data from redis, but it blocked..and no exception raised...just 
freeze
and remove spawn method ,it will worked..
i feel confuse what happened, plz help!
thk u!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python on a MacBook Pro (not my machine)

2013-10-26 Thread Shao Hong
Hi John,

In my college, we are using Python 3.x to teach and personally I am using a
Mac and it works well so far. But back to development work, I use 2.7x
because of libraries I using.

As for ide, we are using IDLE, we understand it is clumsy but it is the
most basic and since it comes with it, so why not make use of it. But my
personal choice will be Sublime and pyCharm or even vim.




Shao Hong
shaohon...@gmail.com

"Respect needs to be earned, but honour is an attitude of the heart. Not
everyone will earn your respect, but everyone deserves to be shown honour."
- Anonymous


On Sun, Oct 27, 2013 at 3:07 AM, John Ladasky wrote:

> Hi folks,
>
> My side job as a Python tutor continues to grow.  In two weeks, I will
> start working with a high-school student who owns a MacBook Pro.
>
> I have had students with Linux systems (my preference) and Windows systems
> before, but not Macs.  On my first visit, I set up each student's computer
> with Python 3.x, and SciTE for editing.  I would like to do something
> similar for my Mac student, and I want to make sure that it goes smoothly.
>
> My first question is whether Mac OS X ships with Python 2.x, and whether I
> need to be aware of any compatibility issues when I install 3.x.  (It's
> 2013, and my students are new to programming.  I refuse to hitch them to
> Python 2.)
>
> Second: it doesn't look like I will be able to obtain SciTE for this
> student.  SciTE is free for Windows and Linux.  Apparently, it's $42 for
> Mac OSX?  If I recall, SciTE is open-source, so I suppose that I could
> compile the source myself.  But since it is not my computer, and I'm being
> paid for my time, and I haven't done much with Macs (to say nothing of
> building from source code), I don't think that this is appropriate.
>
> I know, we can use IDLE.  I continue to find IDLE clumsy.  Also, there are
> potential issues with event handling which arise when you use IDLE.  I am
> working with an adult professional who is developing a Telnet application,
> which refuses to cooperate with IDLE/Tk.  I had similar issues myself with
> wxPython applications I was writing.  While these issues may not affect a
> beginning student, these experiences have informed my choices.
>
> So, what other free and lightweight editing options do I have for a Mac?
>  I have found a few (fairly old) discussions on comp.lang.python which
> suggest Eric (http://eric-ide.python-projects.org/) and Editra (
> http://editra.org/).  Opinions on these and other choices are appreciated.
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Question on threads

2008-04-11 Thread Jonathan Shao
Hi all,

I'm a beginner to Python, so please bear with me.

Is there a way of guarenteeing that all created threads in a program are
finished before the main program exits? I know that using join() can
guarentee this, but from the test scripts I've run, it seems like join()
also forces each individual thread to terminate first before the next thread
can finish. So if I create like 20 threads in a for loop, and I join() each
created thread, then join() will in effect cause the threads to be executed
in serial rather than in parallel.

~ Jon

-- 
"Perhaps we all give the best of our hearts uncritically, to those who
hardly think about us in return."
~ T.H.White
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Question on threads

2008-04-11 Thread Jonathan Shao
On Fri, Apr 11, 2008 at 3:29 PM, Steve Holden <[EMAIL PROTECTED]> wrote:

> Jonathan Shao wrote:
>
> > Hi all,
> >  I'm a beginner to Python, so please bear with me.
> >  Is there a way of guarenteeing that all created threads in a program
> > are finished before the main program exits? I know that using join() can
> > guarentee this, but from the test scripts I've run, it seems like join()
> > also forces each individual thread to terminate first before the next thread
> > can finish. So if I create like 20 threads in a for loop, and I join() each
> > created thread, then join() will in effect cause the threads to be executed
> > in serial rather than in parallel.
> >
> >
> No it won't, as in fact there is no mechanism to force a thread to
> terminate in Python. When you join() each created thread the main thread
> will wait for each thread to finish. Supposing the longest-lived thread
> finished first then all others will immediately return from join().
>
> The only requirement it is imposing is that all sub-threads must be
> finished before the main thread terminates.
>
> regards
>  Steve
> --
> Steve Holden+1 571 484 6266   +1 800 494 3119
> Holden Web LLC  http://www.holdenweb.com/
>


I guess I'm doing something wrong with join(). Here's a test script I wrote
up...

import threading
import time
class TestThread(threading.Thread):
def __init__(self, region):
self.region = region
threading.Thread.__init__(self)
def run(self):
for loop in range(10):
print "Region " + str(self.region) + " reporting: " + str(loop)
time.sleep(2)
for x in range(10):
thr = TestThread(x)
thr.start()
thr.join()
raw_input()
In this script thread 0 will finish first... Am I doing something wrong with
join()?
-- 
http://mail.python.org/mailman/listinfo/python-list

Interesting timing issue I noticed

2008-04-14 Thread Jonathan Shao
The project I'm working on is motion detection, involving a bit of image
processing. No worries: no image processing background needed.

Suffice to say that I initially wrote a script that goes through every pixel
of a 320x240 picture (turned into an array using PIL) and performs some
calculatiosn. It simply goes through every pixel in the array and performs a
simple subtraction with a known value. The idea is to try to find
differences between the two images.

After a while, to try to speed up the calculations, I realized that I didn't
need to do all 320x240 calculations. So I implemented a slightly more
sophisticated algorithm and localized my calculations. I still do the pixel
subtractions, but I do it on a smaller scale.

Surprisingly, when I used time.time() to time the procedures, I find that
doing all 320x240 calculations are often faster! On my machine, the former
gives me on average an execution time of around 0.125s (and consistently),
whereas the latter on average takes 0.160s.

Why does this happen?

-- 
"Perhaps we all give the best of our hearts uncritically, to those who
hardly think about us in return."
~ T.H.White
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Interesting timing issue I noticed

2008-04-15 Thread Jonathan Shao
I've written up a stripped down version of the code. I apologize for the bad
coding; I am in a bit of a hurry.

import random
import sys
import time

sizeX = 320
sizeY = 240
borderX = 20
borderY = 20

# generates a zero matrix
def generate_zero():
matrix = [[0 for y in range(sizeY)] for x in range(sizeX)]
return matrix
# fills zero matrix
def fill_matrix(in_mat):
mat = in_mat
for x in range(sizeX):
for y in range(sizeY):
mat[x][y] = random.randint(1, 100)
return mat
##
# COMPUTES ONLY A PART OF THE ARRAY
def back_diff_one(back_array, fore_array, box):
diff_array = generate_zero()

start = time.time()
for x in range(sizeX):
for y in range(borderY):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]
for y in range((sizeY - borderY), sizeY):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]
for y in range(borderY, (sizeY - borderY)):
for x in range(borderX):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]
for x in range((sizeX - borderX), sizeX):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]

# tracks object
if (len(box) != 0):
for x in range(box[0], box[2]):
for y in range(box[1], box[3]):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]
print "time one inside = " + str(time.time() - start)
return diff_array
##
# COMPUTES EVERY ELEMENT IN THE ARRAY
def back_diff_two(back_array, fore_array):
diff_array = generate_zero()
start = time.time()
for y in range(sizeY):
for x in range(sizeX):
diff_array[x][y] = back_array[x][y] - fore_array[x][y]
end = time.time()
print "time two inside = " + str(end - start)
return diff_array
##
# CODE TO TEST BOTH FUNCTIONS
back = fill_matrix(generate_zero())
fore = fill_matrix(generate_zero())
box = [20, 20, 268, 240]
start1 = time.time()
diff1 = back_diff_one(back, fore, box)
print "time one outside = " + str(time.time() - start1)
start2 = time.time()
diff2 = back_diff_two(back, fore)
print "time one outside = " + str(time.time() - start2)

Here are some results from several test runs:

time one inside = 0.078686646
time one outside = 0.125
time two inside = 0.078686646
time two outside = 0.14132425
>>>  RESTART

>>>
time one inside = 0.062637604
time one outside = 0.125
time two inside = 0.078961853
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.062362396
time one outside = 0.13866486
time two inside = 0.078686646
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.078686646
time one outside = 0.172000169754
time two inside = 0.078961853
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.078686646
time one outside = 0.125
time two inside = 0.078686646
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.062362396
time one outside = 0.155999898911
time two inside = 0.078686646
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.077999830246
time one outside = 0.125
time two inside = 0.077999830246
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.078686646
time one outside = 0.17103815
time two inside = 0.077999830246
time two outside = 0.125
>>>  RESTART

>>>
time one inside = 0.062637604
time one outside = 0.1876376
time two inside = 0.062362396
time two outside = 0.125

Why is a large percentage of the time, the execution time for the
(ostensibly smaller) first loop is actually equal to or LARGER than the
second?

-- 
"Perhaps we all give the best of our hearts uncritically, to those who
hardly think about us in return."
~ T.H.White
-- 
http://mail.python.org/mailman/listinfo/python-list

Interesting timing issue I noticed

2008-04-16 Thread Jonathan Shao
*Gabriel Genellina* gagsl-py2 at yahoo.com.ar

*Wed Apr 16 08:44:10 CEST 2008*
> Another thing would be to rearrange the loops so the outer one executes
less times; if you know that borderX<-- 
http://mail.python.org/mailman/listinfo/python-list

have opensource crawler written by python?

2009-11-02 Thread Junjun Shao
hi,

Is there a crawler written by python? anybody can give me more information?

thanks a lot!
-- 
http://mail.python.org/mailman/listinfo/python-list