[issue15076] Sometimes couldn't import os, shown 'import site' failed, use -v for trackback

2012-06-20 Thread Leon Zhang

Changes by Leon Zhang leozh...@cisco.com:


Removed file: http://bugs.python.org/file26015/pygen.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15076
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15076] Sometimes couldn't import os, shown 'import site' failed, use -v for trackback

2012-06-20 Thread Leon Zhang

Leon Zhang leozh...@cisco.com added the comment:

No people help me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15076
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15076] Sometimes couldn't import os, shown 'import site' failed, use -v for trackback

2012-06-20 Thread Leon Zhang

Leon Zhang leozh...@cisco.com added the comment:

Thank ramchandra.apte for the help.

I checked linecache.py, and the file exists. Unfortunately I don't have root 
perssion to re-install Python. I also checked another bug 
http://bugs.python.org/issue10496;, I think that may be the truth.

Finally I found another workaround, that is to run my Python from shell.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15076
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15076] Sometimes couldn't import os, shown 'import site' failed, use -v for trackback

2012-06-15 Thread Leon Zhang

New submission from Leon Zhang leozh...@cisco.com:

Hello Experts,

I am using Python 2.6.2 on a Linux machine. I found sometimes I have problem to 
run my simple python script.

 Linux version and Python version 
leonz@fxcsgbu2c1% uname -a
SunOS fxcsgbu2c1 5.8 Generic_117350-06 sun4u sparc SUNW,UltraAX-i2
leonz@fxcsgbu2c1% python
Python 2.6.2 (r262:71600, Sep  9 2009, 06:36:48) 
[GCC 3.4.6] on sunos5
Type help, copyright, credits or license for more information.


 Problem description 
I have one python script file located at /usr/autoprog/LogUtility/pygen.py, 
the first 4 lines are:
line 1: #!/usr/bin/python
line 2: import sys
line 3: import os
line 4: import traceback

If I just run python /usr/autoprog/LogUtility/pygen.py from shell, the script 
always worked fine.
We are running another application called autotest on this machine, 
autotest will create a new process and launch Python in this new process 
(/usr/bin/python /usr/autoprog/LogUtility/pygen.py) to run my Python script.
Most of the time, the Python script worked fine, but from some time, for some 
reason, the script suddenty failed, and from this time, if I run autotest to 
luanch my python script, it always fails, but if I run the python script from 
shell, it always works fine. If I reboot this machine, both way to run python 
script works fine. But after some time, run autotest to luanch python script 
will fail again...
Here is the details of the error message of running autotest to luanch python 
script:
'import site' failed; use -v for traceback
Traceback (most recent call last):
File /usr/autoprog/SGBU/LogUtility/pygen.py, line 19, in module
import os
File /usr/local/lib/python2.6/os.py, line 49, in module
import posixpath as path
File /usr/local/lib/python2.6/posixpath.py, line 16, in module
import warnings
File /usr/local/lib/python2.6/warnings.py, line 6, in module
import linecache
ImportError: No module named linecache

 Some other information may help 
I had searched 'import site' failed; use -v for traceback on internet, there 
are also many other people have this problem, but I didn't see any useful 
information to fix my problem.
Here are some information about the Python on my machine:
Install path is /usr/local/lib/python2.6
There is just one README file under /usr/local/lib/python2.6/site-packages

Attached is the python script file pygen.py. Could any expert help me on this 
problem? Appreciate if any experts can reply me. Thanks.

--
components: Library (Lib)
files: pygen.py
messages: 162879
nosy: qtld614
priority: normal
severity: normal
status: open
title: Sometimes couldn't import os, shown 'import site' failed, use -v for 
trackback
type: crash
versions: Python 2.6
Added file: http://bugs.python.org/file26015/pygen.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15076
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: do something in time interval

2008-10-06 Thread Leon Zhang
Petr,

I am not an expert, but why not to use time.sleep(5)?
If you are using wxPython, you may also try wx.Timer, in which you could set
its interval.

Good luck!
Leon

On Tue, Oct 7, 2008 at 2:07 AM, Petr Jakes [EMAIL PROTECTED] wrote:

 I have infinitive loop running script and I would like to check
 something periodically after 5 seconds (minutes, hours...) time period
 (I do not mean time.sleep(5) ). Till now, I have following script, but
 I think there must be something more elegant.

 eventFlag = False
 while 1:
time.sleep(0.01)
seconds = time.time()
if not int(seconds % (5)):
if eventFlag:
print 5 seconds, hurray
eventFlag = False
else:
eventFlag = True

 Best regards

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

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


Re: Socket Question

2008-10-01 Thread Leon Zhang
Maybe you need to close the socket somewhere else, rather than to close it
when you receive the your response.

On Tue, Sep 30, 2008 at 7:01 AM, Ali Hamad [EMAIL PROTECTED] wrote:

 Hello All :

 A socket question from a networking newbie.  I need to create
 a server that:

 1) receive a message from client.
 2) check that message and response to it.
 3) the client get the server message and send another message.
 4) finally, the server receive the message and close the connection.

 I have successfully done this. However, I couldn't use the same socket
 to send the second message
 to the server. I have googled but all the examples are only for sending
 one message and receiving the response.

 in my client code, I have :

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(('127.0.0.1', 1888))
 s.send(1st message)
 response = s.recv(1024)
 validate(response)
 s.send(2nd message)
 response2 = s.recv(1024)
 s.close()

 However, I got the first response just fine from the server but the
 second message didn't get to the server.

 So, the solution I came up with is to send the 1st message, close the
 socket, create new socket,
 and send the 2nd message.

 I came up with something like :

 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(('127.0.0.1', 1888))
 s.send(1st message)
 response = s.recv(1024)
 s.close()
 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 s.connect(('127.0.0.1', 1888))
 s.send(2nd message)
 response = s.recv(1024)
 s.close()

 and it works !

 My Question :

 is it possible to send/receive from the same socket more than one message ?

 Thank you for your assistance in advance,
 --
 http://mail.python.org/mailman/listinfo/python-list

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

the pipe reading in Thread dose not work.

2008-06-01 Thread Leon zhang

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import string, sys
from threading import Thread
import os
import time

class test_pipe(Thread):
def __init__(self, fd):
Thread.__init__(self)
self.testfd = fd

def run(self):
print started thread begin -
while True:
buf = self.testfd.read()
print receive %s % (buf)
time.sleep(1)
#print hoho

if __name__ == __main__:

stdin_r, stdin_w = os.pipe()
#stdout_r, stdout_w = pipe()

f_w = os.fdopen(stdin_w, w, 0)

thrd = test_pipe(os.fdopen(stdin_r, r, 0))
thrd.start()

time.sleep(1)

while True:
f_w.write(help\r\n)
time.sleep(1)

thrd.join()

well, I want the following small test about pipe() in thread().
OK, I write to the pipe in the main thread, and I created a new thread
for reading from the pipe, then it will print what it received from
the pipe().

But, it seems it block at the self.testfd.read().

So, is there and suggestion and explaination about it?

Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list