Giter Site home page Giter Site logo

packtpublishing / expert-python-programming-fourth-edition Goto Github PK

View Code? Open in Web Editor NEW
148.0 11.0 99.0 123 KB

Expert Python Programming, Fourth Edition published by Packt

License: MIT License

Dockerfile 2.06% Python 95.25% HTML 0.07% C++ 0.22% Hy 0.04% C 1.97% Shell 0.03% Cython 0.35%

expert-python-programming-fourth-edition's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

expert-python-programming-fourth-edition's Issues

Error at threaded_visits.py Ch6, Multiprocessing

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

Should itsdangerous and Jinja2 be installed in Dockerfile (Chapter 12, Section 6)?

Problem

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)

Suggestion

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

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`

https://github.com/PacktPublishing/Expert-Python-Programming-Fourth-Edition./blob/ba386da307804d559a279d4cd0eaa76041e3c318/Chapter%209/02%20-%20Pure%20C%20extensions/fibonacci.c#L1

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.