Pickle, __init__, and classes

2005-08-02 Thread Yin
I've created a class that reads in and processes a file in the
initializer __init__.  The processing is fairly substantial, and thus,
instead of processing the file every time the object is created, I
pickle the object to a file.

In subsequent creations of the object, I implement a test to see
whether the pickled file exists.  If it does, then I unpickle the
object.

Unfortunately, the __init__ cannot return this unpickled object.

I've used an auxiliary member function which fixes the problem, but I
would prefer to have the correct object returned at instantiation
rather than returned from the auxiliary member function.

Are there other ways of approaching this problem?

Thanks,
Yin

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


Odd behavior with os.fork and time.sleep

2005-09-16 Thread Yin
I am writing a script that monitors a child process.  If the child
process dies on its own, then the parent continues on.  If the child
process is still alive after a timeout period, the parent will kill the
child process.  Enclosed is a snippet of the code I have written.  For
some reason, unless I put in two time.sleep(4) commands in the parent,
the process will not sleep.  Am I forgetting something?  Any reasons
for this strange behavior?

Linux Fedora Core 4
Python 2.4.1

Thanks.

#!/usr/bin/env python

import os, time
import signal
import sys

def chldhandler(signum, stackframe):
  while 1:
try:
  result = os.waitpid(-1, os.WNOHANG)
except:
  break
print "Reaped child process %s" % result[0]
  signal.signal(signal.SIGCHLD, chldhandler)

signal.signal(signal.SIGCHLD, chldhandler)

pid = os.fork()
if pid:  # parent
  print "Parent.  Child is %d" % pid

  try:
os.kill(pid, 0)
print "Killed child"
os.kill(pid, signal.SIGKILL)
  except OSError, err:
print "Child is dead"

  print "In parent again"
  time.sleep(4)
  time.sleep(4)

  print "Parent awake"
else:  # child
  print "Child sleeping 5 seconds..."
  time.sleep(5)
  print "Child awake"

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


Change directory not successfully done

2005-11-10 Thread Samuel Yin
Hi, guys,

This should be a simple problem, but I just can not resolve it. I just
want to use a python script to change my working directory. see my
following code:

# mycd.py
1) destdir = ""
2) command = "cd "+ destdir
3) os.system(command)
4) os.chdir(destdir)

But neither 3) nor 4) is used, I just can not change the directory after
execute mycd.py. This remind me of bash script. If you change directory
in your bash script file, it will only impact the sub process of that
script, except that you invoke that bash script by ./script_file_name.
But what should I do in the case of python script?

Thanks and Regards

Samuel Yin

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

Re: Change directory not successfully done

2005-11-10 Thread Samuel Yin




Thanks for your answer. I know why the why os.system or os.chdir failed
change my directory. 

But Sorry for my un-clear description of my problem. Currently I work
in window platform, use cmd.exe instead of bash.

I mentioned bash just as a example to illustrate my problem.

    Thanks and Regards

Samuel Yin

Mike Meyer 写道:

  Samuel Yin <[EMAIL PROTECTED]> writes:
  
  
Hi, guys,

This should be a simple problem, but I just can not resolve it. I just
want to use a python script to change my working directory. see my
following code:

# mycd.py
1) destdir = ""
2) command = "cd "+ destdir
3) os.system(command)
4) os.chdir(destdir)

But neither 3) nor 4) is used, I just can not change the directory after
execute mycd.py. This remind me of bash script. If you change directory
in your bash script file, it will only impact the sub process of that
script, except that you invoke that bash script by ./script_file_name.
But what should I do in the case of python script?

  
  
Actually, one solution is a level of indirection worse than the bash
script. Doing a cd changes the current directory of the process that
executes the cd system call. In a bash script, it's the shell
executing the script. In your python script, os.system launches
another process to run the command, and it's *that* process that has
it's directory changed. The os.chdir changes the shell of the python
interpreter, which still doesn't do you any good.

One solution is to switch to a shell that understands Python, and have
that execfile your script. There is a Python environment that can be
configured to be used as a shell, but I can't remeber it's name.

If you want to stay with bash, your solutions are the same as they are
for setting an environment variable in the parent shell.  You can
google for that for a long discussion of the issues.

The solution I liked from that thread was an alias:

In your bash do: alias mycd="eval $(python mycd.py)"

mycd.py looks like:
destdir = 'xx'
command = 'os ' + destdir
print command

At the bash prompt you enter the command "mycd", your python script
builds a command for the shell to execute and prints it, the eval
reads that output and executes it in your shell.

If you want to pass arguments to the python script, you'll need to use
a shell function instead of an alias.

 





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

which specified python module can monitor text information in Windows GUI

2015-01-05 Thread Chambers yin
Which kind of specified python module can monitor text in Windows GUI or
support the similar function?


Br,
-Chambers
-- 
https://mail.python.org/mailman/listinfo/python-list


recommended gcc versions for python2.5 compilation on Solaris sparc/x86, AIX, Linux

2008-07-10 Thread YIN Ming
Dear All,

 

We are going to compile python2.5.1 with gcc on various platforms,
including Solaris8(sparc), Solaris10(x86), AIX and Linux.

 

Just want to check if there are recommended gcc versions for these
platforms. We aim to:

1.  use a single version of  gcc for all platforms

2.  use new version of gcc (rather than odd version)

 

Thanks and best regards,

Yin Ming 
 
 


 This e-mail contains information for the intended recipient only.  It may 
contain proprietary material or confidential information.  If you are not the 
intended recipient you are not authorised to distribute, copy or use this 
e-mail or any attachment to it.  Murex cannot guarantee that it is virus free 
and accepts no responsibility for any loss or damage arising from its use.  If 
you have received this e-mail in error please notify immediately the sender and 
delete the original email received, any attachments and all copies from your 
system.
--
http://mail.python.org/mailman/listinfo/python-list

RE: recommended gcc versions for python2.5 compilation on Solarissparc/x86, AIX, Linux

2008-07-11 Thread YIN Ming
Dear Jeroen,

Thanks so much for your help. :)

Best regards,
Yin Ming

-Original Message-
From: Jeroen Ruigrok van der Werven [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 11, 2008 5:55 PM
To: YIN Ming
Cc: [email protected]; LEGRAND Mathieu
Subject: Re: recommended gcc versions for python2.5 compilation on 
Solarissparc/x86, AIX, Linux

-On [20080711 06:18], YIN Ming ([EMAIL PROTECTED]) wrote:
>2.  use new version of gcc (rather than odd version)

See
http://www.in-nomine.org/2008/04/11/python-26a2-execution-times-with-various-compilers/
 that I wrote a while ago.

Basically for Python GCC 3.4.6 outperformed the newer GCCs. So do not
automatically assume that newer is better.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B
The weak can never forgive. Forgiveness is the attribute of the strong... 
 
 


 This e-mail contains information for the intended recipient only.  It may 
contain proprietary material or confidential information.  If you are not the 
intended recipient you are not authorised to distribute, copy or use this 
e-mail or any attachment to it.  Murex cannot guarantee that it is virus free 
and accepts no responsibility for any loss or damage arising from its use.  If 
you have received this e-mail in error please notify immediately the sender and 
delete the original email received, any attachments and all copies from your 
system.
--
http://mail.python.org/mailman/listinfo/python-list


Compilation problem of Python2.5.1 on AIX5.2 (with --enable-shared option)

2008-04-16 Thread YIN Ming
Dear All,

 

I encountered a problem when compiling Python2.5.1 as shared library on
AIX5.2. Your help are greatly appreciated.

 

In order to embed python into our product, we want to compile python as
shared library.  It works for Solaris and Linux. Unfortunately, It is
for AIX and I could not find solution from Web. Could you help answer
the following questions:

 

Is it feasible to compile python2.5.1 as shared library for AIX5.2? 

or where can I find relevant documentation/info for this?

 

 

So far, the only documents I have are the README and Misc/AIX-NOTES in
the source distribution

The step I tried to compile python as shared library is to follow
README, section "Building a shared libpython", which suggests to add
--enable-shared during configuration.

 

My problem is that with --enable-shared, the make step could not
complete (the error message shows it tries to refer to "-lpython2.5" in
a wrong directory).  Then if I refer it to the correct directory (which
is compiled in source root), some warning messages show duplicated
symbols. And finally I just remove "-lpython2.5", the make could finish
but the resulting python interpreter is a statically-linked binary. (The
detail is shown below).

 

 

The detail of my compilation

 

1.  CC="cc_r" ./configure --prefix=/src/new/python2/install
--without-gcc --disable-ipv6 --enable-shared 
2.  make CC="cc_r" OPT="-O -qmaxmem=4000" 

 

An error occurred when compiling python extensions.

...

running build

running build_ext

INFO: Can't locate Tcl/Tk libs and/or headers

building '_struct' extension

creating build

...

cc_r -DNDEBUG -O -I.
-I/vega5/prod/src/new/python2/Python-2.5.1/./Include -I./In

clude -I. -I/usr/local/include
-I/vega5/prod/src/new/python2/Python-2.5.1/Includ

e -I/vega5/prod/src/new/python2/Python-2.5.1 -c
/vega5/prod/src/new/python2/Pyth

on-2.5.1/Modules/_struct.c -o
build/temp.aix-5.2-2.5/vega5/prod/src/new/python2/

Python-2.5.1/Modules/_struct.o

creating build/lib.aix-5.2-2.5

./Modules/ld_so_aix cc_r -bI:Modules/python.exp
build/temp.aix-5.2-2.5/vega5/pro

d/src/new/python2/Python-2.5.1/Modules/_struct.o -L/usr/local/lib
-lpython2.5 -o

 build/lib.aix-5.2-2.5/_struct.so

ld: 0706-006 Cannot find or open library file: -l python2.5

ld:open(): No such file or directory

*** WARNING: renaming "_struct" since importing it failed: No such file
or directory

error: No such file or directory

make: The error code from the last command is 1.

 

The highlighted command tries to locate the pyhton2.5 lib in
/usr/local/lib, which obviously does not contain this lib.

 

A library, libpython2.5.a, has already been compiled in the root build
directory.

 

1) First, I try to add "-L." to the command

./Modules/ld_so_aix cc_r -bI:Modules/python.exp
build/temp.aix-5.2-2.5/vega5/prod/src/new/python2/Python-2.5.1/Modules/_
struct.o  -L/usr/local/lib -L.

 -lpython2.5 -o  build/lib.aix-5.2-2.5/_struct.so

 

It could find but with a lot of warning messages like:

ld: 0711-224 WARNING: Duplicate symbol: PyObject_GenericGetAttr

ld: 0711-224 WARNING: Duplicate symbol: .PyObject_GenericGetAttr

ld: 0711-224 WARNING: Duplicate symbol: ._Py_ReadyTypes 

...

 

2) Second, I try to remove "-L/usr/local/lib -lpython2.5" from the
command

./Modules/ld_so_aix cc_r -bI:Modules/python.exp
build/temp.aix-5.2-2.5/vega5/prod/src/new/python2/Python-2.5.1/Modules/_
struct.o  -o  build/lib.aix-5.2-2.5/_struct.so

 

It complete without any warning message.

 

As a result, I filter out all "-lpython2.5" passed to
./Modules/ld_so_aix for the rest commands. In this way, the python
interpreter was generated. However, it is a big executable and "ldd
python" does not show it depends on any python shared library (It seems
no shared python library generated). It has no difference from the one
compiled without --enable-shared.

 

Note that if the configuration is run without --enable-shared option,
the corresponding commands will not contain "-lpython2.5".

 

Best regards,

Yin Ming 
 
 


 This e-mail contains information for the intended recipient only.  It may 
contain proprietary material or confidential information.  If you are not the 
intended recipient you are not authorised to distribute, copy or use this 
e-mail or any attachment to it.  Murex cannot guarantee that it is virus free 
and accepts no responsibility for any loss or damage arising from its use.  If 
you have received this e-mail in error please notify immediately the sender and 
delete the original email received, any attachments and all copies from your 
system.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: ignored test cases in unittest

2009-08-15 Thread Terry Yin
Yes, should be more than 200. But now 187+ are running (some are
'ignored').It's
a personal project, I just don't feel safe without all the testing as it
grows bigger and bigger.


On Sun, Aug 16, 2009 at 11:40 AM, John Haggerty  wrote:

> So you are saying you have several hundred tests you have to do on your
> program?
>
> On Sat, Aug 15, 2009 at 7:04 PM, Terry  wrote:
>
>> Hi,
>>
>> I have some 100s unittest cases with my python program. And sometimes,
>> I did quick-and-dirty work by ignoring some test cases by adding an
>> 'x' (or something else) to the beginning of the case name.
>> As time pass by, it's very hard for me to find which test cases are
>> ignored.
>>
>> It seemed the to me that python unittest module does not support the
>> counting of ignored test cases directly. Is there any ready solution
>> for this?
>>
>> br, Terry
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>


-- 
-
Blog: http://terry-yinzhe.spaces.live.com/
twitter: http://twitter.com/terryyin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ignored test cases in unittest

2009-08-17 Thread Terry Yin
On Aug 17, 8:23 pm, David House  wrote: > > Note that the
unittest module now supports the `skip' and > `expectedFailure' decorators,
which seem to describe some of the > solutions here. > > Seehttp://
docs.python.org/3.1/library/unittest.html#skipping-tests-and-e... > > -- >
-David Yes, indeed! I'm using 2.6 now. It seemed I need to copy untitest.py
from 3.1. But the docs.python.org is hell slow from where I am (China), not
even working except the title:-( br, Terry

On Mon, Aug 17, 2009 at 8:23 PM, David House  wrote:

> 2009/8/16 Terry :
> > Thanks for the solutions. I think the decorator idea is what I'm look
> > for:-)
>
> Note that the unittest module now supports the `skip' and
> `expectedFailure' decorators, which seem to describe some of the
> solutions here.
>
> See
> http://docs.python.org/3.1/library/unittest.html#skipping-tests-and-expected-failures
>
> --
> -David
>



-- 
-
Blog: http://terry-yinzhe.spaces.live.com/
twitter: http://twitter.com/terryyin
-- 
http://mail.python.org/mailman/listinfo/python-list


Binary file output using python

2007-04-17 Thread Chi Yin Cheung
Hi,
Is there a way in python to output binary files? I need to python to 
write out a stream of 5 million floating point numbers, separated by 
some separator, but it seems that all python supports natively is string 
information output, which is extremely space inefficient.

I'd tried using the pickle module, but it crashed whenever I tried using 
it due to the large amount of data involved.

Thanks for your help!
-- 
http://mail.python.org/mailman/listinfo/python-list