8000 Merge branch 'main' into fix-stream-reader-protocol-task-strong-refer… · python/cpython@ec8fb92 · GitHub
[go: up one dir, main page]

Skip to content

Commit ec8fb92

Browse files
authored
Merge branch 'main' into fix-stream-reader-protocol-task-strong-reference
2 parents 5289afe + 5b070c0 commit ec8fb92

File tree

6 files changed

+242
-8
lines changed

6 files changed

+242
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*.cover
66
*.iml
77
*.o
8+
*.lto
89
*.a
910
*.so
1011
*.so.*
1112
*.dylib
13+
*.dSYM
1214
*.dll
1315
*.wasm
1416
*.orig

Doc/howto/logging-cookbook.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,88 @@ You can of course use the conventional means of decoration::
26782678
...
26792679

26802680

2681+
.. _buffered-smtp:
2682+
2683+
Sending logging messages to email, with buffering
2684+
-------------------------------------------------
2685+
2686+
To illustrate how you can send log messages via email, so that a set number of
2687+
messages are sent per email, you can subclass
2688+
:class:`~logging.handlers.BufferingHandler`. In the following example, which you can
2689+
adapt to suit your specific needs, a simple test harness is provided which allows you
2690+
to run the script with command line arguments specifying what you typically need to
2691+
send things via SMTP. (Run the downloaded script with the ``-h`` argument to see the
2692+
required and optional arguments.)
2693+
2694+
.. code-block:: python
2695+
2696+
import logging
2697+
import logging.handlers
2698+
import smtplib
2699+
2700+
class BufferingSMTPHandler(logging.handlers.BufferingHandler):
2701+
def __init__(self, mailhost, port, username, password, fromaddr, toaddrs,
2702+
subject, capacity):
2703+
logging.handlers.BufferingHandler.__init__(self, capacity)
2704+
self.mailhost = mailhost
2705+
self.mailport = port
2706+
self.username = username
2707+
self.password = password
2708+
self.fromaddr = fromaddr
2709+
if isinstance(toaddrs, str):
2710+
toaddrs = [toaddrs]
2711+
self.toaddrs = toaddrs
2712+
self.subject = subject
2713+
self.setFormatter(logging.Formatter("%(asctime)s %(levelname)-5s %(message)s"))
2714+
2715+
def flush(self):
2716+
if len(self.buffer) > 0:
2717+
try:
2718+
smtp = smtplib.SMTP(self.mailhost, self.mailport)
2719+
smtp.starttls()
2720+
smtp.login(self.username, self.password)
2721+
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (self.fromaddr, ','.join(self.toaddrs), self.subject)
2722+
for record in self.buffer:
2723+
s = self.format(record)
2724+
msg = msg + s + "\r\n"
2725+
smtp.sendmail(self.fromaddr, self.toaddrs, msg)
2726+
smtp.quit()
2727+
except Exception:
2728+
if logging.raiseExceptions:
2729+
raise
2730+
self.buffer = []
2731+
2732+
if __name__ == '__main__':
2733+
import argparse
2734+
2735+
ap = argparse.ArgumentParser()
2736+
aa = ap.add_argument
2737+
aa('host', metavar='HOST', help='SMTP server')
2738+
aa('--port', '-p', type=int, default=587, help='SMTP port')
2739+
aa('user', metavar='USER', help='SMTP username')
2740+
aa('password', metavar='PASSWORD', help='SMTP password')
2741+
aa('to', metavar='TO', help='Addressee for emails')
2742+
aa('sender', metavar='SENDER', help='Sender email address')
2743+
aa('--subject', '-s',
2744+
default='Test Logging email from Python logging module (buffering)',
2745+
help='Subject of email')
2746+
options = ap.parse_args()
2747+
logger = logging.getLogger()
2748+
logger.setLevel(logging.DEBUG)
2749+
h = BufferingSMTPHandler(options.host, options.port, options.user,
2750+
options.password, options.sender,
2751+
options.to, options.subject, 10)
2752+
logger.addHandler(h)
2753+
for i in range(102):
2754+
logger.info("Info index = %d", i)
2755+
h.flush()
2756+
h.close()
2757+
2758+
If you run this script and your SMTP server is correctly set up, you should find that
2759+
it sends eleven emails to the addressee you specify. The first ten emails will each
2760+
have ten log messages, and the eleventh will have two messages. That makes up 102
2761+
messages as specified in the script.
2762+
26812763
.. _utc-formatting:
26822764

26832765
Formatting times using UTC (GMT) via configuration

Makefile.pre.in

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ DTRACE= @DTRACE@
5454
DFLAGS= @DFLAGS@
5555
DTRACE_HEADERS= @DTRACE_HEADERS@
5656
DTRACE_OBJS= @DTRACE_OBJS@
57+
DSYMUTIL= @DSYMUTIL@
58+
DSYMUTIL_PATH= @DSYMUTIL_PATH@
5759

5860
GNULD= @GNULD@
5961

@@ -576,7 +578,7 @@ LIBEXPAT_HEADERS= \
576578
# Default target
577579
all: @DEF_MAKE_ALL_RULE@
578580
build_all: check-clean-src $(BUILDPYTHON) platform sharedmods \
579-
gdbhooks Programs/_testembed scripts checksharedmods
581+
gdbhooks Programs/_testembed scripts checksharedmods rundsymutil
580582
build_wasm: check-clean-src $(BUILDPYTHON) platform sharedmods \
581583
python-config checksharedmods
582584

@@ -905,6 +907,22 @@ sharedmods: $(SHAREDMODS) pybuilddir.txt
905907
checksharedmods: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
906908
@$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/check_extension_modules.py
907909

910+
rundsymutil: sharedmods $(PYTHON_FOR_BUILD_DEPS) $(BUILDPYTHON)
911+
@if [ ! -z $(DSYMUTIL) ] ; then \
912+
echo $(DSYMUTIL_PATH) $(BUILDPYTHON); \
913+
$(DSYMUTIL_PATH) $(BUILDPYTHON); \
914+
if test -f $(LDLIBRARY); then \
915+
echo $(DSYMUTIL_PATH) $(LDLIBRARY); \
916+
$(DSYMUTIL_PATH) $(LDLIBRARY); \
917+
fi; \
918+
for mod in X $(SHAREDMODS); do \
919+
if test $$mod != X; then \
920+
echo $(DSYMUTIL_PATH) $$mod; \
921+
$(DSYMUTIL_PATH) $$mod; \
922+
fi; \
923+
done \
924+
fi
925+
908926
Modules/Setup.local:
909927
@# Create empty Setup.local when file was deleted by user
910928
echo "# Edit this file for local setup changes" > $@
@@ -1755,9 +1773,14 @@ sharedinstall: $(DESTSHARED) all
17551773
if test $$i != X; then \
17561774
echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
17571775
$(INSTALL_SHARED) $$i $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1776+
if test -d "$$i.dSYM"; then \
1777+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1778+
$(DSYMUTIL_PATH) $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1779+
fi; \
17581780
fi; \
17591781
done
17601782

1783+
17611784
$(DESTSHARED):
17621785
@for i in $(DESTDIRS); \
17631786
do \
@@ -1818,6 +1841,23 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
18181841
-output $(DESTDIR)$(BINDIR)/python$(VERSION)-intel64$(EXE) \
18191842
$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
18201843
fi
1844+
# Install macOS debug information (if available)
1845+
if test -d "$(BUILDPYTHON).dSYM"; then \
1846+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
1847+
$(DSYMUTIL_PATH) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
1848+
fi
1849+
if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
1850+
if test -d "$(LDLIBRARY).dSYM"; then \
1851+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1852+
$(DSYMUTIL_PATH) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
1853+
fi \
1854+
else \
1855+
if test -d "$(LDLIBRARY).dSYM"; then \
1856+
echo $(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
1857+
$(DSYMUTIL_PATH) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(INSTSONAME); \
1858+
fi \
1859+
fi
1860+
18211861

18221862
bininstall: altbininstall
18231863
if test ! -d $(DESTDIR)$(LIBPC); then \
@@ -2392,6 +2432,7 @@ clean-retain-profile: pycremoval
23922432
find . -name '*.[oa]' -exec rm -f {} ';'
23932433
find . -name '*.s[ol]' -exec rm -f {} ';'
23942434
find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
2435+
find . -name '*.lto' -exec rm -f {} ';'
23952436
find . -name '*.wasm' -exec rm -f {} ';'
23962437
find . -name '*.lst' -exec rm -f {} ';'
23972438
find build -name 'fficonfig.h' -exec rm -f {} ';' || true
@@ -2508,7 +2549,7 @@ Python/thread.o: @THREADHEADERS@ $(srcdir)/Python/condvar.h
25082549

25092550
# Declare targets that aren't real files
25102551
.PHONY: all build_all build_wasm check-clean-src
2511-
.PHONY: sharedmods checksharedmods test quicktest
2552+
.PHONY: sharedmods checksharedmods test quicktest rundsymutil
25122553
.PHONY: install altinstall sharedinstall bininstall altbininstall
25132554
.PHONY: maninstall libinstall inclinstall libainstall
25142555
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a new ``--with-dsymutil`` configure option to to link debug information
2+
in macOS. Patch by Pablo Galindo.

configure

Lines changed: 83 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

configure.ac

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,10 +1863,10 @@ if test "$Py_LTO" = 'true' ; then
18631863
# Any changes made here should be reflected in the GCC+Darwin case below
18641864
if test $Py_LTO_POLICY = default
18651865
then
1866-
LTOFLAGS="-flto -Wl,-export_dynamic"
1866+
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
18671867
LTOCFLAGS="-flto"
18681868
else
1869-
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic"
1869+
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
18701870
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
18711871
fi
18721872
;;
@@ -1896,7 +1896,7 @@ if test "$Py_LTO" = 'true' ; then
18961896
LDFLAGS_NOLTO="-fno-lto"
18971897
case $ac_sys_system in
18981898
Darwin*)
1899-
LTOFLAGS="-flto -Wl,-export_dynamic"
1899+
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
19001900
LTOCFLAGS="-flto"
19011901
;;
19021902
*)
@@ -3053,6 +3053,33 @@ else
30533053
AC_MSG_RESULT(no)
30543054
fi
30553055

3056+
# Check for --with-dsymutil
3057+
AC_SUBST(DSYMUTIL)
3058+
AC_SUBST(DSYMUTIL_PATH)
3059+
DSYMUTIL=
3060+
DSYMUTIL_PATH=
3061+
AC_MSG_CHECKING(for --with-dsymutil)
3062+
AC_ARG_WITH(dsymutil,
3063+
AS_HELP_STRING([--with-dsymutil], [link debug information into final executable with dsymutil in macOS (default is no)]),
3064+
[
3065+
if test "$withval" != no
3066+
then
3067+
if test "$MACHDEP" != "darwin"; then
3068+
AC_MSG_ERROR([dsymutil debug linking is only available in macOS.])
3069+
fi
3070+
AC_MSG_RESULT(yes);
3071+
DSYMUTIL='true'
3072+
else AC_MSG_RESULT(no); DSYMUTIL=
3073+
fi],
3074+
[AC_MSG_RESULT(no)])
3075+
3076+
if test "$DSYMUTIL"; then
3077+
AC_PATH_PROG(DSYMUTIL_PATH, [dsymutil], [not found])
3078+
if test "$DSYMUTIL_PATH" = "not found"; then
3079+
AC_MSG_ERROR([dsymutil command not found on \$PATH])
3080+
fi
3081+
fi
3082+
30563083
AC_MSG_CHECKING(for dyld)
30573084
case $ac_sys_system/$ac_sys_release in
30583085
Darwin/*)

0 commit comments

Comments
 (0)
0