Posts

Showing posts from March, 2021

ThreadPool in Python

  from concurrent . futures import ThreadPoolExecutor import asyncio import time import threading x = 1 def run_forever1 ( lock ): global x while x < 1000 : print ( f'----start1 acc------ { threading . current_thread (). name } -' ) lock . acquire () print ( f'----start1 acced------ { threading . current_thread (). name } -' ) if x < 1000 : print ( f'----run 1------ { threading . current_thread (). name } -' ) x = x + 1 lock . release () print ( f'----start1 release------ { threading . current_thread (). name } -' ) def run_forever2 ( lock ): global x while x < 1000 : print ( f'----start2 acc------ { threading . current_thread (). name } -' ) lock . acquire () print ( f'----start2 acced------ { threading . current_thread (). name } -' ) if x < 1000 : print ( f'----run 2------ { threading . cur...

Python encrypt and decrypt

file encrypt.py # pip install cryptography import sys from cryptography . fernet import Fernet import hashlib import base64 path = '' key = '' if __name__ == "__main__" : path = str ( sys . argv [ 1 ]) key = base64 . b64encode ( hashlib . md5 ( str ( sys . argv [ 2 ]). encode ()). hexdigest (). encode ()) cipher_suite = Fernet ( key ) file = open ( path , 'r' ) s = file . read () file . close () cipher_text = cipher_suite . encrypt ( s . encode ()) file2 = open ( path , 'w+' ) file2 . write (( cipher_text . decode ())) file2 . close () file decrypt.py # pip install cryptography import sys from cryptography . fernet import Fernet import hashlib import base64 path = '' key = '' if __name__ == "__main__" : path = str ( sys . argv [ 1 ]) key = base64 . b64encode ( hashlib . md5 ( str ( sys . argv [ 2 ]). encode ()). hexdigest (). encode ()) cipher_suite = Fernet ( key ) file = open ( path , 'r' ) s ...