packtpublishing / expert-python-programming-fourth-edition Goto Github PK
View Code? Open in Web Editor NEWExpert Python Programming, Fourth Edition published by Packt
License: MIT License
Expert Python Programming, Fourth Edition published by Packt
License: MIT License
Hi there,
Concurrency is great topic. I followed the code regarding threaded_visits.py. Authors argued that when I will run the file, I will get unexpected results. However, I am getting expected 10_000_000 value for thread_visits.
My hypothesis: There might be changes in threading standard library.
Looking for your reply!
from threading import Thread
thread_visits = 0
def visit_counter():
global thread_visits
for i in range(100_000):
# value = thread_visits
thread_visits += 1
if __name__ == "__main__":
thread_count = 100
threads = [
Thread(target=visit_counter)
for _ in range(thread_count)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print(f"{thread_count=}, {thread_visits=}")
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
In the Chapter 12, Section 6, docker-compose reports error for app_1.
app_1 | Traceback (most recent call last):
app_1 | File "/app/tracking.py", line 3, in <module>
app_1 | from flask import Flask, request, Response
app_1 | File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 14, in <module>
app_1 | from jinja2 import escape
app_1 | ImportError: cannot import name 'escape' from 'jinja2' (/usr/local/lib/python3.9/site-packages/jinja2/__init__.py)
I think that itsdangerous and Jinja2 should be installed explicitly like below (c.f. Flask issue).
RUN pip install \
Flask==1.1.2 \
redis==3.5.3 \
Flask_Injector==0.12.3 \
prometheus-client==0.10.1 \
jaeger-client==4.4.0 \
opentracing==2.4.0 \
'Werkzeug<2.0.0' \
Flask-OpenTracing==1.1.0 \
itsdangerous==2.0.1 \
Jinja2==3.0.3
(The versions of its dangerous and Jinja2 are just example. No specific reason.)
With this change, the docker-compose error resolved and API request(http://localhost:8000/test) succeeded
Cannot Clone Repository from this location.
Also if I fork the repository. I cannot clone it from the fork location.
Please #define PY_SSIZE_T_CLEAN
before #include <Python.h>
.
See https://docs.python.org/3.10/c-api/arg.html#strings-and-buffers
Note For all # variants of formats (s#, y#, etc.), the macro PY_SSIZE_T_CLEAN must be defined before including Python.h. On Python 3.9 and older, the type of the length argument is Py_ssize_t if the PY_SSIZE_T_CLEAN macro is defined, or int otherwise.
Your sample code doesn't use '#' format so it is not mandatory. But "define PY_SSIZE_T_CLEAN
always" is good advice for new extension authors.
15days ago ,so ,its quickly?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.