- matches 0 or 1 repetition of a char/set
- also works as a Non-greedy pattern (with repeaters)
- means in string '<b>Hello</b>' pattern r'<.*>' will match the whole string instead of '<b>'
- but if pattern is used as r'<.*?>' then will match '<b>' only
- AKA pcre (Perl Compatible Regular Expression)
- \t matches a tab
- \r matches a carriage return (line break) in Mac, \n\r in Windows
- \n matches a line break ( carriage return) in Linux & Windows
- note: On "old" printers, \r sent the print head back to the start of the line, and \n advanced the paper by one line. Both were therefore necessary to start printing on the next line.
- matches the boundary between word and non-word chars
- matches the position called word boundaries
- match has zero length
- usually before (including start of the line) and after a word
-e.g. <here>apple<here>
i.e. prevents multiple threads to execute python (byte)codes at once inorder to protect access to python objects
i.e. provides lock to protect shared mutable state
The lock is necessary because CPython's Interpreter or memory management is not thread safe
for example, when two threads simultaneously increment the reference count of the same object, the reference count could end up being incremented only once instead of twice.
hence, GIL is here to make python thread-safe, wherever needed
GIL is controversial because due to it python's multithreading lack few features like
python's multithreaded codes cannot utilize multiprocessor system
the longer operations like I/O, image processing happens outside the GIL
it is only bottleneck for codes which enter GIL for longer time
GIL can causes scheduling IO-bound threads ahead of a CPU-bound threads
inshort, GIL is only bad for multi-core CPU - bound thread operations
each forked process have separate GIL
Jython, IronPython does not have GIL
writing a C extension needs GIL
in Cython the GIL exists, but can be released temporarily using a "with" statement - read more
The join() method, when used with threading or multiprocessing, is not related to str.join()
it's not actually concatenating anything together
It just means "wait for this [thread/process] to complete"
The name join is used because the multiprocessing module's API is meant to look as similar to the threading module's API
The reason why is called join is that is joining the processes into a single one.
Note:
* By default, when the main process is ready to exit, it will implicitly call join() on all running multiprocessing Process instances
* This isn't as clearly stated in the multiprocessing docs as it should be, but it is mentioned in the Programming Guidelines section.
* non-daemonic processes will be automatically be joined.
* can override this behavior by setting the daemon flag on the Process to True prior to starting the process:
1 2 3 4 5 6 7 8 9101112
frommultiprocessingimportProcessimportosdefsay_hello():print("Hello")p=Process(target=say_hello)p.daemon=Truep.start()# Both parent and child will exit here, since the main process has completed.# the child process will be terminated as soon as the main process completes:
Freezing Python code on Linux into a Windows executable was only once supported in PyInstaller and later dropped
All solutions need MS Visual C++ dll to be installed on target machine, except py2app. Only Pyinstaller makes self-executable exe that bundles the dll when passing --onefile to Configure.py.
where
- __init__.py should contain a variable name='example_pkg'
- setup.py should look like this gist
- where classifiers can be like this or gist
- README.md should be present, which will define the long_description about the package
- LICENSE should be accurate with the list
- packages
- if want to includes all the packages/subpackages
- use defaultone packages=setuptools.find_packages(),
- else define manually like
- packages=['pkg1', 'pkg2', 'pkg2.pkg2_1']
Note: After installing the package, you able to import packages with names listed in packages var.
#setuptools & wheel - to create build in .whl as well as .tar.gz. format
python3 -m pip install --user --upgrade setuptools wheel
#twine - to upload build in pypi server
python3 -m pip install --user --upgrade twine