Errata

Introducing Python

Errata for Introducing Python

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
PDF PDF page 264, section Processes

In Chapter 11, H3 sub-section "Processes", the code sample "dishes.py" blows up shortly after starting. Here's the program's output:

------ Begin Trace ------
D:\>python dishes.py
Washing salad dish
Washing bread dish
Washing entree dish
Washing dessert dish
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Python35\lib\multiprocessing\spawn.py", line 106, in spawn_main
exitcode = _main(fd)
File "D:\Python35\lib\multiprocessing\spawn.py", line 115, in _main
prepare(preparation_data)
File "D:\Python35\lib\multiprocessing\spawn.py", line 226, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\Python35\lib\multiprocessing\spawn.py", line 278, in _fixup_main_from_path

run_name="__mp_main__")
File "D:\Python35\lib\runpy.py", line 254, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\Python35\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\Python35\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\EclipseNEON\EclipseWorkspaces\EclipsePythonWorkspace\PythonLessons\IntroducingPython\SystemsProcesses\processesQueueing01.py", line 19, in <module>
dryer_proc.start()
File "D:\Python35\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "D:\Python35\lib\multiprocessing\context.py", line 212, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\Python35\lib\multiprocessing\context.py", line 313, in _Popen
return Popen(process_obj)
File "D:\Python35\lib\multiprocessing\popen_spawn_win32.py", line 34, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\Python35\lib\multiprocessing\spawn.py", line 144, in get_preparation_data
_check_not_importing_main()
File "D:\Python35\lib\multiprocessing\spawn.py", line 137, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:

if __name__ == '__main__':
freeze_support()
...

The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "processesQueueing01.py", line 23, in <module>
dish_queue.join()
File "D:\Python35\lib\multiprocessing\queues.py", line 314, in join
self._cond.wait()
File "D:\Python35\lib\multiprocessing\synchronize.py", line 262, in wait
return self._wait_semaphore.acquire(True, timeout)
KeyboardInterrupt

D:\>
------ End Trace ------

The expected output is:

------ Begin Expected Output ------
$ python dishes.py
Washing salad dish
Washing bread dish
Washing entree dish
Washing dessert dish
Drying salad dish
Drying bread dish
Drying entree dish
Drying dessert dish
------End Expected Output ------

RBVanDyke  Dec 22, 2016 
ePub Page 161
code and results

The result of the first code block is said to be:
This creates the file villains with these lines:

Doctor,No
Rosa,Klebb
Mister,Big
Auric,Goldfinger
Ernst,Blofeld

When I run the code on a Windows PC under Python 3.6.4, the file produced has 11 lines, with 1 blank line after the first four names and 2 blank lines after the last line

-------------------------------------------------------------------------------------------
When the file is read, the result is supposed to be
>>> print(villains)
[['Doctor', 'No'], ['Rosa', 'Klebb'], ['Mister', 'Big'],
['Auric', 'Goldfinger'], ['Ernst', 'Blofeld']]

Instead, there is an emply list [] after each name list, so 10 total inner lists.


Gregory Sherman  Mar 27, 2018 
ePub Page 162, 163
code and results

bascially the same problem as reported with the previous CSV code

Extra blank lines are produced in the output file (1 after the header and each name, with the exception of 2 after the last name)

The results of reading the file and printing "villains" are closer to what is in the book, but the actual structure is a list of "OrderedDict"

Gregory Sherman  Mar 27, 2018 
Printed Page 266
continued code from previous page

for n in range(2):
dryer_thread = threading.Thread(target=dryer, args=(dish_queue,))
dryer_thread.start()
dishes = ['salad', 'bread', 'entree', 'dessert']
washer(dishes, dish_queue)
dish_queue.join()

setDaemon is not set to True. Program won't exit without this statement.

Anonymous  Nov 28, 2017