[issue40053] Document the behavior that no interplotation is applied when no *args are passed in for logging statements

2020-03-26 Thread Nan Hua


Nan Hua  added the comment:

Note that this issue has already been mostly addressed by 
https://github.com/python/cpython/pull/19132. I think we can close this issue 
now. Thanks Eric, Gregory and Vinay!

--
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue40053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40053] Document the behavior that no interplotation is applied when no *args are passed in for logging statements

2020-03-24 Thread Nan Hua


New submission from Nan Hua :

As I see, Python's logging module's implementation has a nice property that, 
when no additional args are passed in, the msg (first argument) will be 
directly printed.

For example, logging.error('abc %s') can be handled peacefully with printing 
"ERROR:root:abc %s" in the log.

However, the logging's documentation only said the followings:
"The msg is the message format string, and the args are the arguments which are 
merged into msg using the string formatting operator."

>From what I see, this implementation (seems the case for both Python2 and 
>Python3) has many benefits: saving CPU resources, safe handling pre-formated 
>string, etc. More importantly, it also de-facto allows using the convenient 
>f-string in logging statement, e.g. 

logging.error(f'Started at {start_time}, finished at {finish_time}'
  f' by user {user}')

can run correctly and smoothly even with user containing %s inside.

In summary, I hope this de-facto actual behavior can be officially endorsed, 
with wordings like,
"When *args is empty, i.e. no additional positional arguments passed in, the 
msg be of any string (no need to be a format string) and will be directly used 
as is without interpolation."

What do you think? Thank you a lot!

--
components: Library (Lib)
messages: 364920
nosy: nhua
priority: normal
severity: normal
status: open
title: Document the behavior that no interplotation is applied when no *args 
are passed in for logging statements
type: behavior
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue40053>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30367] Cannot build CPython3.6 with module “testcapimodule” statically

2017-05-14 Thread Nan Zhang

New submission from Nan Zhang:

up vote
0
down vote
favorite
I am trying to build CPython3.6 from GitHub statically with the Documentation 
below:

https://wiki.python.org/moin/BuildStatically

Changed *shared* to *static*

And only uncommented the module "testcapimodule" in Modules/Setup file:

_testcapi _testcapimodule.c # Python C API test module

And ran with 'make LINKFORSHARED=" "'

However I got errors that:

gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 
-Wall -Wstrict-prototypes-std=c99 -Wextra -Wno-unused-result 
-Wno-unused-parameter -Wno-missing-field-initializers   -I. -I./Include
-DPy_BUILD_CORE  -c ./Modules/_testcapimodule.c -o Modules/_testcapimodule.o
./Modules/_testcapimodule.c: In function ‘test_datetime_capi’:
./Modules/_testcapimodule.c:2191:9: error: ‘PyDateTimeAPI’ undeclared 
(first use in this function)
 if (PyDateTimeAPI) {
 ^
./Modules/_testcapimodule.c:2191:9: note: each undeclared identifier is 
reported only once for each function it appears in
./Modules/_testcapimodule.c:2203:5: error: ‘PyDateTime_IMPORT’ 
undeclared (first use in this function)
 PyDateTime_IMPORT;
 ^
./Modules/_testcapimodule.c:2208:1: warning: control reaches end of 
non-void function [-Wreturn-type]
 }
 ^
make: *** [Modules/_testcapimodule.o] Error 1

But when I build Cpython3.6 with *shared*, it can succeed.

--
components: Build
messages: 293664
nosy: Nan Zhang
priority: normal
severity: normal
status: open
title: Cannot build CPython3.6 with module “testcapimodule” statically
type: compile error
versions: Python 3.6

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



[issue26747] types.InstanceType only for old style class only in 2.7

2016-04-13 Thread Nan Wu

New submission from Nan Wu:

>>> import types
>>> a = 1
>>> isinstance(a, types.InstanceType)
False
>>> class A:
... pass
... 
>>> a = A()
>>> isinstance(a, types.InstanceType)
True
>>> class A(object):
... pass
... 
>>> a = A()
>>> isinstance(a, types.InstanceType)
False

Looks like isinstance(instance, types.InstanceType) only return True for 
user-defined old-style class instance. If it's the case, I feel doc should 
clarify that like what types.ClassType did. If no, someone please close this 
request. Thanks.

--
files: doc_InstanceType_is_for_old_style_cls.patch
keywords: patch
messages: 263338
nosy: Nan Wu
priority: normal
severity: normal
status: open
title: types.InstanceType only for old style class only in 2.7
type: enhancement
versions: Python 2.7
Added file: 
http://bugs.python.org/file42456/doc_InstanceType_is_for_old_style_cls.patch

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



[issue25783] test_traceback.test_walk_stack() fails when run directly (without regrtest)

2015-12-03 Thread Nan Wu

Nan Wu added the comment:

Put in a fix. Let me know if it looks ok.

--
nosy: +Nan Wu
Added file: 
http://bugs.python.org/file41232/fix_test_walk_stack_failed_as_script_patch

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



[issue25755] Test test_property failed if run twice

2015-12-03 Thread Nan Wu

Nan Wu added the comment:

Thanks for catching this failure. In the patch, property doc is restore after 
write operation.

--
nosy: +Nan Wu
Added file: 
http://bugs.python.org/file41233/fix_test_property_doc_writable_patch

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



[issue25651] Confusing output for TestCase.subTest(0)

2015-11-21 Thread Nan Wu

Nan Wu added the comment:

Made it check against None explicitly. My concern is if [] is passed in, if 
will show [[]]. But this case should be rare.

--
keywords: +patch
nosy: +Nan Wu
Added file: 
http://bugs.python.org/file41115/subtest_msg_check_against_None.patch

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



[issue25609] Add a ContextManager ABC and type

2015-11-12 Thread Nan Wu

Nan Wu added the comment:

Hi Brett, I'd like work on this feature. Your description here is clear. 
Besides that, could you give a use case of this context manager?

--
nosy: +Nan Wu

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



[issue25567] shlex.quote doesn't work on bytestrings

2015-11-09 Thread Nan Wu

Nan Wu added the comment:

Added a patch for support this in `quote` method. What is a good example or a 
group of examples to demonstrate the usage in the document?

--
keywords: +patch
nosy: +Nan Wu
Added file: http://bugs.python.org/file40992/shlex_quote_bytes_support.patch

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



[issue25439] Add type checks to urllib.request.Request

2015-10-31 Thread Nan Wu

Nan Wu added the comment:

Martin: Sorry for missing that line.

Under https, byte iterable seems has not been supported:
>>> r = Request('https://www.python.org', {b'post': 'data'}, 
>>> {'Content-Length':10})
>>> urlopen(r)

... hanging here...

Meanwhile, I assumed bytearray works as expected.
>>> r = Request('https://www.python.org', bytearray('post=data', 'utf-8'))
>>> urlopen(r)


urllib.error.HTTPError: HTTP Error 403: FORBIDDEN

In *4.patch, I updated Request class doc to add these observations and fixed 
issues appeared in last patch.

--
Added file: 
http://bugs.python.org/file40912/urllib_request_param_type_check_4.patch

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



[issue25439] Add type checks to urllib.request.Request

2015-10-27 Thread Nan Wu

Nan Wu added the comment:

The do_request_() method which is defined in AbstractHTTPHandler seems not 
cover the check at least for the first case Ezio brought up. `unknown_open` has 
been called and gives out a relatively confusing message.

--

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



[issue25439] Add type checks to urllib.request.Request

2015-10-27 Thread Nan Wu

Nan Wu added the comment:

Will fix the other two issues. Thanks.

--

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



[issue25439] Add type checks to urllib.request.Request

2015-10-25 Thread Nan Wu

Changes by Nan Wu <nanbytesf...@gmail.com>:


Added file: 
http://bugs.python.org/file40850/urllib_request_param_type_check_3.patch

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



[issue25017] htmllib deprecated: Which library to use? Missing sane default in docs

2015-10-21 Thread Nan Wu

Nan Wu added the comment:

Updated the patch. The typo was fixed too. Thanks for the catching.

--
Added file: http://bugs.python.org/file40831/htmllib_deprecation_warning_2.patch

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



[issue25439] Add type checks to urllib.request.Request

2015-10-20 Thread Nan Wu

Nan Wu added the comment:

Uploaded a patch. Also update the test. Seems there are at least two old test 
cases using empty dict as data param. has dict been supported before?

--
keywords: +patch
nosy: +Nan Wu
Added file: 
http://bugs.python.org/file40819/urllib_request_param_type_check.patch

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



[issue25439] Add type checks to urllib.request.Request

2015-10-20 Thread Nan Wu

Nan Wu added the comment:

I see. Empty dict is considered as iterable of bytes makes good sense. I just 
left the old tests there. And explicitly give warnings when data field is of 
type str or type dict with non-bytes key.

--
Added file: 
http://bugs.python.org/file40830/urllib_request_param_type_check_2.patch

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



[issue25017] htmllib deprecated: Which library to use? Missing sane default in docs

2015-10-16 Thread Nan Wu

Nan Wu added the comment:

Added a small patched for this change.

--
keywords: +patch
nosy: +Nan Wu
Added file: http://bugs.python.org/file40796/htmllib_deprecation_warning.patch

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



[issue25322] contextlib.suppress not tested for nested usage

2015-10-07 Thread Nan Wu

Nan Wu added the comment:

Added a patch with Martina's idea. Isn't ignored better set as false instead ? 
Since interpreter did not ignore it.

--
keywords: +patch
nosy: +Nan Wu
Added file: http://bugs.python.org/file40713/fix_reentrant_cm_test.patch

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



[issue25311] Add f-string support to tokenize.py

2015-10-07 Thread Nan Wu

Nan Wu added the comment:

Added 'f'/'F' to the StringPrefix regex and also update the quote dictionary.

--
keywords: +patch
nosy: +Nan Wu
Added file: http://bugs.python.org/file40712/tokenize.patch

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



[issue24479] Support LMMS project files in mimetypes.guess_type

2015-07-22 Thread Nan Wu

Nan Wu added the comment:

Added a small patch. Pls let me know if anything missed.

--
nosy: +bytesflow
Added file: 
http://bugs.python.org/file39989/issue24479_support_mmp_and_mmpz_suffix_in_guess_type

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



[issue21502] freeze.py not working properly on Mac OSX 10.9

2014-05-13 Thread Jiang-Nan Yang

New submission from Jiang-Nan Yang:

Command:
python3.4 
/Library/Frameworks/Python.framework/Versions/3.4/share/doc/python3.4/examples/Tools/freeze/freeze.py
 okcointrade.py

Error:
Reporting needed directory %s not found

Basically the problem is on lines 235~239: config should be config-3.4m, 
python%s on two lines should be python%sm

After I corrected these errors, the command works, asking me to run make, 
except a warning about unknown modules remains.

So I run make, another error occurs:
gcc-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c 
M_difflib.c
gcc-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c 
M_ftplib.c
gcc-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m 
-I/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c 
M_pydoc.c
gcc-4.2  -Wl,-stack_size,100  -framework CoreFoundation 
Python.framework/Versions/3.4/Python config.o frozen.o M___future__.o 
M___main__.o M__bootlocale.o M__collections_abc.o M__dummy_thread.o 
M__osx_support.o M__sitebuiltins.o M__strptime.o M__sysconfigdata.o 
M__threading_local.o M__weakrefset.o M_abc.o M_argparse.o M_ast.o M_base64.o 
M_bdb.o M_bisect.o M_bz2.o M_calendar.o M_cmd.o M_code.o M_codecs.o M_codeop.o 
M_collections.o M_contextlib.o M_copy.o M_copyreg.o M_datetime.o M_difflib.o 
M_dis.o M_distutils.o M_distutils__errors.o M_distutils__log.o 
M_distutils__spawn.o M_distutils__sysconfig.o M_distutils__text_file.o 
M_doctest.o M_dummy_threading.o M_email.o M_email___encoded_words.o 
M_email___header_value_parser.o M_email___parseaddr.o M_email___policybase.o 
M_email__base64mime.o M_email__charset.o M_email__contentmanager.o 
M_email__encoders.o M_email__errors.o M_email__feedparser.o 
M_email__generator.o M_email__header.o M_email__headerregistry.o 
M_email__iterators.o M_email
 __message.o M_email__parser.o M_email__policy.o M_email__quoprimime.o 
M_email__utils.o M_encodings.o M_encodings__aliases.o M_encodings__latin_1.o 
M_encodings__utf_8.o M_enum.o M_fnmatch.o M_ftplib.o M_functools.o 
M_genericpath.o M_getopt.o M_getpass.o M_gettext.o M_glob.o M_gzip.o 
M_hashlib.o M_heapq.o M_html.o M_html__entities.o M_http.o M_http__client.o 
M_http__cookiejar.o M_http__server.o M_imp.o M_importlib.o 
M_importlib___bootstrap.o M_importlib__machinery.o M_importlib__util.o 
M_inspect.o M_io.o M_json.o M_json__decoder.o M_json__encoder.o 
M_json__scanner.o M_keyword.o M_linecache.o M_locale.o M_logging.o M_lzma.o 
M_mimetypes.o M_ntpath.o M_nturl2path.o M_opcode.o M_operator.o M_optparse.o 
M_os.o M_pdb.o M_pkgutil.o M_platform.o M_plistlib.o M_posixpath.o M_pprint.o 
M_py_compile.o M_pydoc.o M_pydoc_data.o M_pydoc_data__topics.o M_quopri.o 
M_random.o M_re.o M_reprlib.o M_rlcompleter.o M_selectors.o M_shlex.o 
M_shutil.o M_site.o M_socket.o M_socketserver.o M_sre_compile.o M_sre
 _constants.o M_sre_parse.o M_ssl.o M_stat.o M_string.o M_struct.o 
M_subprocess.o M_sysconfig.o M_tarfile.o M_tempfile.o M_textwrap.o 
M_threading.o M_token.o M_tokenize.o M_traceback.o M_tty.o M_types.o 
M_unittest.o M_unittest__case.o M_unittest__loader.o M_unittest__main.o 
M_unittest__result.o M_unittest__runner.o M_unittest__signals.o 
M_unittest__suite.o M_unittest__util.o M_urllib.o M_urllib__error.o 
M_urllib__parse.o M_urllib__request.o M_urllib__response.o M_uu.o M_warnings.o 
M_weakref.o M_webbrowser.o M_xml.o M_xml__parsers.o M_xml__parsers__expat.o 
M_zipfile.o 
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/config-3.4m/libpython3.4.a
   -ldl  -framework CoreFoundation   -o okcointrade
clang: error: no such file or directory: 'Python.framework/Versions/3.4/Python'
make: *** [okcointrade] Error 1

I guess that 'Python.framework/Versions/3.4/Python' using a relative location 
might be a problem, so I go into the Makefile, changed 
PYTHONFRAMEWORKDIR=Python.framework
into
PYTHONFRAMEWORKDIR=/Library/Frameworks/Python.framework

Now the above problem disappeared, but a new appeared:
gcc-4.2  -Wl,-stack_size,100  -framework CoreFoundation 
/Library/Frameworks/Python.framework/Versions/3.4/Python config.o frozen.o 
M___future__.o M___main__.o M__bootlocale.o M__collections_abc.o 
M__dummy_thread.o M__osx_support.o M__sitebuiltins.o M__strptime.o 
M__sysconfigdata.o M__threading_local.o M__weakrefset.o M_abc.o M_argparse.o 
M_ast.o M_base64.o M_bdb.o M_bisect.o M_bz2.o M_calendar.o M_cmd.o M_code.o 
M_codecs.o M_codeop.o M_collections.o M_contextlib.o M_copy.o M_copyreg.o 
M_datetime.o M_difflib.o M_dis.o M_distutils.o M_distutils__errors.o 
M_distutils__log.o M_distutils__spawn.o M_distutils__sysconfig.o 
M_distutils__text_file.o M_doctest.o

[issue21502] freeze.py not working properly on Mac OSX 10.9

2014-05-13 Thread Jiang-Nan Yang

Changes by Jiang-Nan Yang yjiang...@gmail.com:


--
nosy:  -ronaldoussoren, yjiangnan
versions: +Python 3.3

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



Re: subprocess.Popen calling httpd reload never finishes

2010-08-18 Thread Nan
On Aug 17, 8:14 pm, Albert Hopkins mar...@letterboxes.org wrote:
 On Tue, 2010-08-17 at 12:55 -0700, Nan wrote:
  Hi folks --

  I have a Python script running under Apache/mod_wsgi that needs to
  reload Apache configs as part of its operation.  The script continues
  to execute after the subprocess.Popen call.  The communicate() method
  returns the correct text (Reloading httpd: [  OK  ]), and I get a
  returncode of 0.  But the python script (Django) that calls Popen
  never seems to complete (by returning an HTTP response.

  Any other Popen call I've tried exits properly.  Here's some sample
  code:

             args = ['sudo /etc/init.d/httpd reload']
             proc = subprocess.Popen(args, stdin=subprocess.PIPE,
  stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True,
  close_fds=True)
             (stdout_txt, stderr_txt) = proc.communicate()
             proc.wait()
             logging.debug('%d %shr /%s' % (proc.returncode, stdout_txt,
  stderr_txt))
             logging.debug('still executing')
             return HttpResponse('done')

  The logging statements are output, but the script doesn't exit.  If
  you substitute sudo ls -l or sudo /etc/init.d/httpd configtest for
  sudo /etc/init.d/httpd reload, the exits properly.

   Any idea what I might be doing wrong?

  Thanks!

 Django runs inside apache.  It's kinda weird to have an apache process
 restart itself and expect it to return to the caller.

 If the init script does like mine, reload executes apachectl -k
 graceful   What that instructs apache to do is to restart, but only
 kill the process(es) when there are no more connections.  So apache is
 waiting for your connection to close, but you are inside an HTTP request
 waiting for apache to restart.  So you have a race condition here.

 It's not advisable to have apache kill itself and expect it to send a
 status back to you telling you it's dead.

 See the apache docs[1] for a better explanation.

 http://httpd.apache.org/docs/2.0/stopping.html#graceful

Ah, I'd been told that there would be no conflict, and that this was
just reloading the configuration, not restarting Apache.

I do need the web app to instruct Apache to reload because just before
this it's creating new VirtualHosts that need to be recognized.  Is
there a better way to do this (e.g. to say start doing this once I'm
finished)?

I'm getting a status code and output from the call before the Django
script stops executing... Is there a way to stop waiting for the
process to complete once I have those?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: subprocess.Popen calling httpd reload never finishes

2010-08-18 Thread Nan
On Aug 18, 12:37 pm, Albert Hopkins mar...@letterboxes.org wrote:
 On Wed, 2010-08-18 at 06:58 -0700, Nan wrote:
  Ah, I'd been told that there would be no conflict, and that this was
  just reloading the configuration, not restarting Apache.

  I do need the web app to instruct Apache to reload because just before
  this it's creating new VirtualHosts that need to be recognized.  Is
  there a better way to do this (e.g. to say start doing this once I'm
  finished)?

  I'm getting a status code and output from the call before the Django
  script stops executing... Is there a way to stop waiting for the
  process to complete once I have those?

 I have a wireless router with a built in web server.  Sometimes it needs
 to reload it's config.  Basically what it's doing is rebooting the
 entire router (I can see this if I'm actuall watching the router).  All
 it is doing, I'm pretty sure, is calling some program that forks another
 process and then exits the main program.  The forked process then
 reboots the router.  Meanwhile before that happens the web server sends
 a response. Basically in the response it sends an HTTP Refresh with x
 number of seconds.  Presumably x is longer than the time it requires for
 the router to reboot.  The router reboots, the browser refreshes and
 viola.

 You probably need to so something similar in that your request calls a
 program that forks off and restarts apaches.  It should probably not do
 so immediately so that your request has time to send a response with a
 refresh header (but that shouldn't take long).  After a second or so,
 apache will have restarted and the browser will have refreshed.

 so (untested):

 def reload(request):
     subprocess.call(['my_apache_reloader']) # this should fork and exit
     response = HttpResponse()
     response['Refresh']='3; url=%s' % reverse(home) # chk back in 3 secs
     return response

 BTW There is a Django mailing list where this might be more appropriate
 to discuss.

 -a

Sadly, questions about subprocess spawning on the Django lists seem to
get referred back to the Python lists when they get an answer at all.
You've been very helpful, though, so thank you.

I think I'll have to mark in the database when the server needs
restarting, and run a cron job to check that and reload Apache from a
non-Apache process.  It will mean delayed creation of the Virtual
Hosts and no immediate feedback to indicate success or failure, but it
doesn't look like there's much alternative.
-- 
http://mail.python.org/mailman/listinfo/python-list


subprocess.Popen calling httpd reload never finishes

2010-08-17 Thread Nan
Hi folks --

I have a Python script running under Apache/mod_wsgi that needs to
reload Apache configs as part of its operation.  The script continues
to execute after the subprocess.Popen call.  The communicate() method
returns the correct text (Reloading httpd: [  OK  ]), and I get a
returncode of 0.  But the python script (Django) that calls Popen
never seems to complete (by returning an HTTP response.

Any other Popen call I've tried exits properly.  Here's some sample
code:

args = ['sudo /etc/init.d/httpd reload']
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True,
close_fds=True)
(stdout_txt, stderr_txt) = proc.communicate()
proc.wait()
logging.debug('%d %shr /%s' % (proc.returncode, stdout_txt,
stderr_txt))
logging.debug('still executing')
return HttpResponse('done')

The logging statements are output, but the script doesn't exit.  If
you substitute sudo ls -l or sudo /etc/init.d/httpd configtest for
sudo /etc/init.d/httpd reload, the exits properly.

 Any idea what I might be doing wrong?

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


virtualenv / virtualenvwrapper resetting $PATH?

2010-06-16 Thread Nan
I just installed virtualenv and virtualenvwrapper on an OS X machine
(10.6).  My ~/.bash_login adds a few paths to the $PATH environment
variable, but upon activating a virtualenv with workon, those paths
go missing from $PATH (and are not restored when I deactivate the
virtualenv either).

Any suggestions as to what I might be doing wrong?

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


newbie question

2008-11-26 Thread Nan
Hello,
   I just started to use Python. I wrote the following code and
expected 'main' would be called.

def main():
  print hello

main

But I was wrong. I have to use 'main()' to invoke main. The python
interpreter does not give any warnings for the above code. Is there
any way/tool to easily detect this kind of errors ?

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


Re: Regexp problem with `('

2007-03-22 Thread Zeng Nan
On Thu, Mar 22, 2007 at 01:26:22AM -0700, Johny wrote:
 I have  the following text
 
 titleGoods Item  146 (174459989)  - OurWebSite/title
 
 from which I need to extract
 `Goods Item  146 '
 
 Can anyone help with regexp?
 Thank you for help
 L.

(Goods\s+Item\s+146\s+)

-- 
Zeng Nan   

MY BLOG: http://zengnan.blogspot.com
Public Key: http://pgp.mit.edu/ | www.keyserver.net

~~~
In Lexington, Kentucky, it's illegal to carry an ice cream cone in your
pocket.

~~~


pgp46CeY9IZzI.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Translate this to python?

2006-01-03 Thread Zeng Nan
On Tue, Jan 03, 2006 at 05:42:44PM -0800, KraftDiner wrote:
 I'm porting a routing from C++ to python.
 There is a complex for loop that I don't know how to code in python
 
 for (i = nPoints-1, j = 0; j  nPoints; i = j, j++)
 

i = nPoints - 1
for j in range(nPoints):
statements
i = j
-- 
Zeng Nan   
Simple is Beautiful.

MY BLOG: http://zengnan.blogspot.com


pgpGFuV3FkTgH.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list