From fc6cdc264a57d4565a12497c2fae3b7da6009ad1 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Sun, 27 Mar 2022 21:55:47 +0700 Subject: [PATCH 01/16] update folder studi kasus --- .../__pycache__/do_something.cpython-310.pyc | Bin 422 -> 378 bytes Chapter01/classes.py | 10 +++---- Chapter01/dir.py | 11 ++++++-- Chapter01/file.py | 18 ++++++------ Chapter01/studiKasus/classes_studikasus.py | 13 +++++++++ Chapter01/studiKasus/dir_studikasus.py | 26 ++++++++++++++++++ Chapter01/studiKasus/file_studikasus.py | 15 ++++++++++ Chapter01/studiKasus/list_studikasus.py | 20 ++++++++++++++ Chapter01/test.txt => test.txt | 0 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 Chapter01/studiKasus/classes_studikasus.py create mode 100644 Chapter01/studiKasus/dir_studikasus.py create mode 100644 Chapter01/studiKasus/file_studikasus.py create mode 100644 Chapter01/studiKasus/list_studikasus.py rename Chapter01/test.txt => test.txt (100%) diff --git a/Chapter01/__pycache__/do_something.cpython-310.pyc b/Chapter01/__pycache__/do_something.cpython-310.pyc index 4f7725209efd94ea3eab2f36bb61b5241cc6bf95..fb67fcd085fc2681e47b3e17ab1ab5397d62bc7e 100644 GIT binary patch delta 95 zcmZ3+{ELYjtML=jWy9x~627WC9iECKi{Z7R5McBo+W^1H+h<{P@YDjHv+jC^5?b diff --git a/Chapter01/classes.py b/Chapter01/classes.py index 9b46a2c..f420e2d 100644 --- a/Chapter01/classes.py +++ b/Chapter01/classes.py @@ -1,12 +1,12 @@ class namakelas: common = 10 - def __init__ (self): + def __init__ (self): #memanggil constructor self.myvariable = 3 - def myfunction (self, arg1, arg2): + def myfunction (self, arg1, arg2): #instance method return self.myvariable instance = namakelas() -print("instance.myfunction(1, 2)" , instance.myfunction(1, 2)) +print("instance.myfunction(1, 2)" , instance.myfunction(1, 2)) #memanggil instance method instance2 = namakelas() print("instance.common ",instance.common) @@ -36,10 +36,10 @@ def __init__ (self, arg1): print (arg1) instance = AnotherClass ("hello") -print("instance.myfunction (1, 2) " , instance.myfunction (1, 2)) +print("instance.myfunction (1, 2) " , instance.myfunction (1, 2)) #memanggil instance method instance.test = 10 -print("instance.test " , instance.test) +print("instance.test " , instance.test) #memanggil instance method diff --git a/Chapter01/dir.py b/Chapter01/dir.py index 65da81d..1721572 100644 --- a/Chapter01/dir.py +++ b/Chapter01/dir.py @@ -2,7 +2,7 @@ # kami memeriksa apakah angkanya positif atau negatif atau nol dan # tampilkan pesan yang sesuai -num = 1 +num = 0 # Try these two variations as well: # num = 0 @@ -23,7 +23,8 @@ numbers = [6, 6, 3, 8, -3, 2, 5, 44, 12] # variable to store the sum -sum = 0 +sum = -35 +# sum = 0 # iterate over the list for val in numbers: @@ -32,3 +33,9 @@ # Output: The sum is 48 print("The sum is", sum) +if sum > 0: + print("Positive number") +elif sum == 0: + print("Zero") +else: + print("Negative number") \ No newline at end of file diff --git a/Chapter01/file.py b/Chapter01/file.py index 15d4e26..2e17f8d 100644 --- a/Chapter01/file.py +++ b/Chapter01/file.py @@ -1,11 +1,13 @@ -f = open ('test.txt', 'w') -f.write ('first line of file \n') +f = open ('test.txt', 'w') #menulis dalam format text. +f.write ('first line of file \n') #menulis string didalam file yang telah dibuka -f.write ('second line of file \n') +f.write ('second line of file \n') #menulis string didalam file yang telah dibuka + +f.close() #menutup file +f = open ('test.txt') #membuka file pada direktori saat ini untuk dibaca +content = f.read() #membaca string dari file +print (content) #menampilkan konten yang ada didalam file + +f.close() #menutup file -f.close() -f = open ('test.txt') -content = f.read() -print (content) -f.close() diff --git a/Chapter01/studiKasus/classes_studikasus.py b/Chapter01/studiKasus/classes_studikasus.py new file mode 100644 index 0000000..3e78849 --- /dev/null +++ b/Chapter01/studiKasus/classes_studikasus.py @@ -0,0 +1,13 @@ +class Karyawan: + def __init__(self, nama, gaji): + self.nama = nama + self.gaji = gaji + + def displayKaryawan(self): + print ("nama : ", self.nama, ", gaji: ", self.gaji) + +emp1 = Karyawan("Udin Wazowski", 2000) +emp2 = Karyawan("Astoria Greengrass", 5000) + +emp1.displayKaryawan() +emp2.displayKaryawan() diff --git a/Chapter01/studiKasus/dir_studikasus.py b/Chapter01/studiKasus/dir_studikasus.py new file mode 100644 index 0000000..4275697 --- /dev/null +++ b/Chapter01/studiKasus/dir_studikasus.py @@ -0,0 +1,26 @@ +gaji = int(input('Masukan Gaji Karyawan Anda: ')) + +if gaji > 1000000: + print("Selamat Menikmati Uang hasil Kerja Anda") +elif gaji == 0: + print("Kasian Kena PHK") +else: + print("UMR BANGET") + + +########### +numbers = [6, 6, 3, 8, -3, 2, 5, 44, 12] + +sum = int(input('Masukan Angka Bebas: ')) +# sum = 0 +for val in numbers: + sum = sum+val + +print("The sum is", sum) + +if sum > 0: + print("Positive number") +elif sum == 0: + print("Zero") +else: + print("Negative number") \ No newline at end of file diff --git a/Chapter01/studiKasus/file_studikasus.py b/Chapter01/studiKasus/file_studikasus.py new file mode 100644 index 0000000..7f871ef --- /dev/null +++ b/Chapter01/studiKasus/file_studikasus.py @@ -0,0 +1,15 @@ +f = open ('file_studikasus.txt', 'w') #menulis dalam format text. +nama = input('Masukan Nama Anda :') +alamat = input('Masukan Alamat Anda :') +hobi = input('Masukan Hobi Anda :') +f.write (nama + '\n') #menulis string didalam file yang telah dibuka + +f.write (alamat + '\n') #menulis string didalam file yang telah dibuka +f.write (hobi + '\n') + +f.close() #menutup file +f = open ('file_studikasus.txt') #membuka file pada direktori saat ini untuk dibaca +content = f.read() #membaca string dari file +print (content) #menampilkan konten yang ada didalam file + +f.close() #menutup file diff --git a/Chapter01/studiKasus/list_studikasus.py b/Chapter01/studiKasus/list_studikasus.py new file mode 100644 index 0000000..7efb64a --- /dev/null +++ b/Chapter01/studiKasus/list_studikasus.py @@ -0,0 +1,20 @@ +list_Perusahaan = ["Tech, Inc", 200000000, "Indddie", 10000000] #list +print(list_Perusahaan) +list_Perusahaan[0] +print(list_Perusahaan[0]) +list_Perusahaan[-1] +print (list_Perusahaan[-1]) + +dict_perusahaan = {"nama_perusahaan":"Tech, Inc", "nama_ceo":"Mamank Racing"} #dictionary +print(dict_perusahaan) +dict_perusahaan["nama_perusahaan"] +print(dict_perusahaan["nama_perusahaan"]) + +dict_2 = {1:"Udin Wazowski", 2:"Test Doang", 3:"Siapa Ya"} +print(dict_2) + +status_perusahaan = ("Aktif", "Nonaktif") #tuple +print(status_perusahaan) + +panjangData = len +print (panjangData(list_Perusahaan)) diff --git a/Chapter01/test.txt b/test.txt similarity index 100% rename from Chapter01/test.txt rename to test.txt From 9ed9d9bb2d6a1663a08981fbe2edde18d2f70fa5 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Mon, 28 Mar 2022 19:21:27 +0700 Subject: [PATCH 02/16] new update studi kasus --- Chapter01/multiprocessing_test.py | 12 ++++---- Chapter01/multithreading_test.py | 10 +++---- .../studiKasus/multiprocessing_studikasus.py | 29 +++++++++++++++++++ .../studiKasus/multithread_studikasus.py | 0 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 Chapter01/studiKasus/multiprocessing_studikasus.py create mode 100644 Chapter01/studiKasus/multithread_studikasus.py diff --git a/Chapter01/multiprocessing_test.py b/Chapter01/multiprocessing_test.py index 2480586..3cdc7f1 100644 --- a/Chapter01/multiprocessing_test.py +++ b/Chapter01/multiprocessing_test.py @@ -3,23 +3,23 @@ import multiprocessing -if __name__ == "__main__": +if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport. start_time = time.time() size = 10000000 procs = 10 jobs = [] - for i in range(0, procs): + for i in range(0, procs): #Membuat proses out_list = list() process = multiprocessing.Process\ - (target=do_something,args=(size,out_list)) + (target=do_something,args=(size,out_list)) # Menginisiasi proses dengan argument jobs.append(process) for j in jobs: - j.start() + j.start() # memulai proses - for j in jobs: + for j in jobs: # menyelesaikan proses j.join() - print ("List processing complete.") + print ("List processing complete.") # proses selesai end_time = time.time() print("multiprocesses time=", end_time - start_time) diff --git a/Chapter01/multithreading_test.py b/Chapter01/multithreading_test.py index 055abdd..d0ddc41 100644 --- a/Chapter01/multithreading_test.py +++ b/Chapter01/multithreading_test.py @@ -2,23 +2,23 @@ import time import threading -if __name__ == "__main__": +if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport. start_time = time.time() size = 10000000 threads = 10 jobs = [] for i in range(0, threads): out_list = list() - thread = threading.Thread(target=do_something(size, out_list)) + thread = threading.Thread(target=do_something(size, out_list)) # Membuat Thread jobs.append(thread) for j in jobs: - j.start() + j.start() # memulai proses for j in jobs: - j.join() + j.join() # menyelesaikan proses - print ("List processing complete.") + print ("List processing complete.") #proses selesai end_time = time.time() print("multithreading time=", end_time - start_time) diff --git a/Chapter01/studiKasus/multiprocessing_studikasus.py b/Chapter01/studiKasus/multiprocessing_studikasus.py new file mode 100644 index 0000000..2fa933f --- /dev/null +++ b/Chapter01/studiKasus/multiprocessing_studikasus.py @@ -0,0 +1,29 @@ + +from multiprocessing import Process +import time + +def karyawan(daftar='Asia'): + print('Nama Karyawan : ', daftar) + +if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport. + start_time = time.time() + names = ['Udin Wazowski', 'Jon cool', 'Asoyy gamink'] + procs = [] + proc = Process(target=karyawan) # Menginisiasi proses tanpa argument + procs.append(proc) + proc.start() + + # Menjalankan proses dengan argumen + for name in names: + # print(name) + proc = Process(target=karyawan, args=(name,)) + procs.append(proc) + proc.start() + + # menyelesaikan proses + for proc in procs: + proc.join() + + print ("List processing complete.") # proses selesai + end_time = time.time() + print("multiprocesses time=", end_time - start_time) \ No newline at end of file diff --git a/Chapter01/studiKasus/multithread_studikasus.py b/Chapter01/studiKasus/multithread_studikasus.py new file mode 100644 index 0000000..e69de29 From 5c295f17b45dd35ce4826085597fdc9265f83c03 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Mon, 28 Mar 2022 22:49:49 +0700 Subject: [PATCH 03/16] update new --- .../__pycache__/do_studikasus.cpython-310.pyc | Bin 0 -> 404 bytes .../__pycache__/wadah.cpython-310.pyc | Bin 0 -> 644 bytes Chapter01/studiKasus/dir_studikasus.py | 10 +++-- Chapter01/studiKasus/do_studikasus.py | 3 ++ .../studiKasus/multiprocessing_studikasus.py | 35 +++++++----------- .../studiKasus/multithread_studikasus.py | 0 6 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc create mode 100644 Chapter01/studiKasus/__pycache__/wadah.cpython-310.pyc create mode 100644 Chapter01/studiKasus/do_studikasus.py delete mode 100644 Chapter01/studiKasus/multithread_studikasus.py diff --git a/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc b/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0129fd6368878d060c0ee44e14ad29b6466b69cf GIT binary patch literal 404 zcmZ8d!Ab)$5KXogigd-3=Un%o=(UJgiU%!}Vk<&fDAP@7i@*t|FJwk|FdQMbip96|+?;1s|I=tgjv3scX+NQGZ+-SuTt+Tq@x4Np>5^|~1 z`fvm}upyWV)}UCAMYL%bMk*HtO*_%0aklWCBiVW#e(> zR$3j8!GICj+@eY3Y$}Wu3o!rBlk3U!>NXy%pm4&Rp2gOcTn@pOHs*T1VX0>)Mb(5( oJIJ;vsek_-LWdqu)5c{K{mxCY9q^*2bDnEnX5wPw^PkuyKNP=ckpKVy literal 0 HcmV?d00001 diff --git a/Chapter01/studiKasus/__pycache__/wadah.cpython-310.pyc b/Chapter01/studiKasus/__pycache__/wadah.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e9f81f38205a1ccce06558fe33b2cda350d4dcc0 GIT binary patch literal 644 zcmZWn&1%~~5T02{wrlLrh7#IaPX!%n(o>-r(~#s)3MSM!35T%OF1A2F>s_fOMLMZ3 zkT+ zZ}9?JZ2a1%NU!l~R(tQDVcX|5{=l03B=&8;WHq*K4siT)O~XU%;2@6Q@h(Ws3Bej_ zxal`Y9K_tRd$wg%%evB?pbYJ5LT1_I)MD}gx=;3>m3+TEQz}hjUM59umREP>rpVu1 zam}?%Z%txKnZ3G}+Q=2x|ArSI7uT1cm**R)ZK6HVL*-S@&Bxz8|sL_$0Iz(0S<9QpMFNJ kdFVyG{czglb 1000000: print("Selamat Menikmati Uang hasil Kerja Anda") elif gaji == 0: - print("Kasian Kena PHK") + print("Anda tidak digaji :(") else: - print("UMR BANGET") + print("Jangan Boros ya.") ########### -numbers = [6, 6, 3, 8, -3, 2, 5, 44, 12] +numbers = [13, 15, 20, 22, -99, 50, 4] sum = int(input('Masukan Angka Bebas: ')) # sum = 0 @@ -23,4 +23,6 @@ elif sum == 0: print("Zero") else: - print("Negative number") \ No newline at end of file + print("Negative number") + + diff --git a/Chapter01/studiKasus/do_studikasus.py b/Chapter01/studiKasus/do_studikasus.py new file mode 100644 index 0000000..5a8b3a4 --- /dev/null +++ b/Chapter01/studiKasus/do_studikasus.py @@ -0,0 +1,3 @@ +def totalKaryawan(count, list_karyawan): + list_karyawan = ['Udin Wazowski', 'Jon cool', 'Asoyy gamink'] + print('Nama Karyawan : ', list_karyawan) \ No newline at end of file diff --git a/Chapter01/studiKasus/multiprocessing_studikasus.py b/Chapter01/studiKasus/multiprocessing_studikasus.py index 2fa933f..47952f4 100644 --- a/Chapter01/studiKasus/multiprocessing_studikasus.py +++ b/Chapter01/studiKasus/multiprocessing_studikasus.py @@ -1,29 +1,22 @@ - -from multiprocessing import Process +from do_studikasus import totalKaryawan import time +import multiprocessing -def karyawan(daftar='Asia'): - print('Nama Karyawan : ', daftar) - -if __name__ == "__main__": # Memastikan code ada pada main function/tidak diimport. +if __name__ == "__main__": start_time = time.time() - names = ['Udin Wazowski', 'Jon cool', 'Asoyy gamink'] - procs = [] - proc = Process(target=karyawan) # Menginisiasi proses tanpa argument - procs.append(proc) - proc.start() + count = 3 + list_karyawan = [] + out_list = list() + process = multiprocessing.Process\ + (target=totalKaryawan,args=(count,out_list)) + list_karyawan.append(process) - # Menjalankan proses dengan argumen - for name in names: - # print(name) - proc = Process(target=karyawan, args=(name,)) - procs.append(proc) - proc.start() + for j in list_karyawan: + j.start() - # menyelesaikan proses - for proc in procs: - proc.join() + for j in list_karyawan: + j.join() - print ("List processing complete.") # proses selesai + print ("List processing complete.") end_time = time.time() print("multiprocesses time=", end_time - start_time) \ No newline at end of file diff --git a/Chapter01/studiKasus/multithread_studikasus.py b/Chapter01/studiKasus/multithread_studikasus.py deleted file mode 100644 index e69de29..0000000 From 5555f9c8006e772e9510822b4f9ba0e13d320e59 Mon Sep 17 00:00:00 2001 From: burhanudinzuhri Date: Mon, 28 Mar 2022 22:54:04 +0700 Subject: [PATCH 04/16] Update Flow & Multithreading --- .../__pycache__/do_studikasus.cpython-310.pyc | Bin 404 -> 386 bytes Chapter01/studiKasus/flow_studikasus.py | 50 ++++++++++++++++++ .../studiKasus/multithreading_studikasus.py | 23 ++++++++ 3 files changed, 73 insertions(+) create mode 100644 Chapter01/studiKasus/flow_studikasus.py create mode 100644 Chapter01/studiKasus/multithreading_studikasus.py diff --git a/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc b/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc index 0129fd6368878d060c0ee44e14ad29b6466b69cf..040b5977c9cd04826ecf8e0fb67ae0268d76a7e3 100644 GIT binary patch delta 52 zcmbQj+{Db4&&$ij00e= 75: + print("Selamat Anda Lolos") +elif nilai == 0: + print("Anda Tidak Ikut Ujian") +else: + print("Anda Ikut Remedial") + + +# FOR +durasi_kerja = float(input('masukan durasi kerja: ')) + +if durasi_kerja > 8: + print("Durasi Kerja + Lembur") +elif durasi_kerja == 8: + print("Durasi Kerja Rata-rata") +else: + print("Durasi Kerja Dibawah Rata-Rata") + + +############1 +total_durasi_kerja = [7,8,9] + +durasi_lembur = 4 +for val in total_durasi_kerja: + durasi_lembur = durasi_lembur+val + +print("Total Semua Durasi Kerja", durasi_lembur) + +if durasi_lembur > 12.00: + print("CAPEK") +elif durasi_lembur == 0.00: + print("Anda Kerja ?") +else: + print("Kerja Santai") + + +#WHILE +# Program to add natural numbers upto sum = 1+2+3+...+n + +n = 10 +# initialize sum and counter +sum = 0 +i = 1 +while i <= n: + sum = sum + i + i = i+1 # update counter + +# print the sum +print("The sum is", sum) \ No newline at end of file diff --git a/Chapter01/studiKasus/multithreading_studikasus.py b/Chapter01/studiKasus/multithreading_studikasus.py new file mode 100644 index 0000000..3755eb2 --- /dev/null +++ b/Chapter01/studiKasus/multithreading_studikasus.py @@ -0,0 +1,23 @@ +from do_studikasus import totalKaryawan +import time +import threading + +if __name__ == "__main__": + start_time = time.time() + count = 10 + procs = 1 + process = [] + for i in range(0, procs): + out_list = list() + thread = threading.Thread(target=totalKaryawan(count,out_list)) + process.append(thread) + + for j in process: + j.start() + + for j in process: + j.join() + + print ("List processing complete.") + end_time = time.time() + print("multithreading time=", end_time - start_time) \ No newline at end of file From 59ae457c476f206149e392bbc7f2effe0e38b0cb Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Tue, 29 Mar 2022 20:49:20 +0700 Subject: [PATCH 05/16] multiprocessing update --- .../__pycache__/do_studikasus.cpython-310.pyc | Bin 386 -> 404 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc b/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc index 040b5977c9cd04826ecf8e0fb67ae0268d76a7e3..0129fd6368878d060c0ee44e14ad29b6466b69cf 100644 GIT binary patch delta 69 zcmZo-p2EzP&&$ij00e(dOyoMNpOtDA<5*CTlbM`Yl9``Z91~Dkl98XM8<1F(Sd^L* XUz}N7lA5a!l3G-pnv_^H@k<{78&MgO delta 52 zcmbQj+{Db4&&$ij00e Date: Tue, 29 Mar 2022 22:07:38 +0700 Subject: [PATCH 06/16] new update lagi --- Chapter01/studiKasus/classes_studikasus.py | 21 +++++++++++++++++++++ Chapter01/studiKasus/file_studikasus.py | 16 ++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Chapter01/studiKasus/classes_studikasus.py b/Chapter01/studiKasus/classes_studikasus.py index 3e78849..68777ea 100644 --- a/Chapter01/studiKasus/classes_studikasus.py +++ b/Chapter01/studiKasus/classes_studikasus.py @@ -11,3 +11,24 @@ def displayKaryawan(self): emp1.displayKaryawan() emp2.displayKaryawan() + +emp1 = Karyawan("Koro koro", 8000) +emp2 = Karyawan("Kucu kucu", 5000) + +emp1.displayKaryawan() +emp2.displayKaryawan() + +class Posisi(Karyawan): + def __init__(self, nama, posisi, gaji): + self.nama = nama + self.posisi = posisi + self.gaji = gaji + + def display(self): + print("Nama : ", self.nama, ", posisi : ", self.posisi, ", gaji : ", self.gaji) + +emp1 = Posisi("TTesting", 'Software Engineer', 4000) +emp2 = Posisi("Astoria", 'HRD', 5000) + +emp1.display() +emp2.display() diff --git a/Chapter01/studiKasus/file_studikasus.py b/Chapter01/studiKasus/file_studikasus.py index 7f871ef..44e5a1f 100644 --- a/Chapter01/studiKasus/file_studikasus.py +++ b/Chapter01/studiKasus/file_studikasus.py @@ -1,15 +1,15 @@ -f = open ('file_studikasus.txt', 'w') #menulis dalam format text. +f = open ('file_studikasus.txt', 'w') nama = input('Masukan Nama Anda :') alamat = input('Masukan Alamat Anda :') hobi = input('Masukan Hobi Anda :') -f.write (nama + '\n') #menulis string didalam file yang telah dibuka +f.write (nama + '\n') -f.write (alamat + '\n') #menulis string didalam file yang telah dibuka +f.write (alamat + '\n') f.write (hobi + '\n') -f.close() #menutup file -f = open ('file_studikasus.txt') #membuka file pada direktori saat ini untuk dibaca -content = f.read() #membaca string dari file -print (content) #menampilkan konten yang ada didalam file +f.close() +f = open ('file_studikasus.txt') +content = f.read() +print (content) -f.close() #menutup file +f.close() From 50c869d49610538941dc2a65ffb1f89973b06467 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Wed, 30 Mar 2022 09:57:44 +0700 Subject: [PATCH 07/16] update --- .../__pycache__/do_studikasus.cpython-310.pyc | Bin 404 -> 432 bytes .../__pycache__/do_studikasus.cpython-39.pyc | Bin 0 -> 402 bytes Chapter01/studiKasus/do_studikasus.py | 5 +++-- Chapter01/studiKasus/list_studikasus.py | 4 +++- .../studiKasus/multiprocessing_studikasus.py | 13 ++++++++----- .../studiKasus/multithreading_studikasus.py | 6 +++--- 6 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 Chapter01/studiKasus/__pycache__/do_studikasus.cpython-39.pyc diff --git a/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc b/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-310.pyc index 0129fd6368878d060c0ee44e14ad29b6466b69cf..fee56d7ef33dd5d6ba828107d0878a365cf9d1f6 100644 GIT binary patch delta 171 zcmbQjyn&fFpO=@50SI0laZcJhk=MqM8OUJ)VrL*ORsj+v3^feRj4lkZ+_g;U3@MC@ z7;70z7*m*P7@L_G846h@<~Zvy-C`|D%u7$b#ad95nOCC8e2X^-xFkM1 zv8Xb!JTdPUW9CYRBG!qQo3%KACi5_IF!C_6{3~Jya{M$I!E_NTkb^|9O|D^-007DN BC{q9c delta 145 zcmdnMJcXGzpO=@50SNw_a7>yxk=I6<3CLjvVrL*O76TIL3@MC@7;70z7*d#O7@L_G z875Xab1~jxEhx&&E74?{cutIEB|{PO#MjMsEI{=fjC_nmtU!jJCWI~m8HYrG6y4&m U$<0qG%}KRm1oDbOmhvzF0Cnpdq5uE@ diff --git a/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-39.pyc b/Chapter01/studiKasus/__pycache__/do_studikasus.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fd7f561c506b22ec25c120a4cf037e8b65cbbb80 GIT binary patch literal 402 zcmZ8c!AiqG5Zz6!6luVd=e_2j=(UJgN)K8n#Z&|dlxa4!Ym(ityP+iLss4mlZ~lqj zkgK2IO*}YTEffddynW1j%q;l+0m1ry@6TV5Kb+Vt55* Date: Tue, 5 Apr 2022 23:19:31 +0700 Subject: [PATCH 08/16] chapter 2 --- Chapter02/Condition.py | 4 +- Chapter02/studiKasus/Barrier_studikasus.py | 29 ++++++++ .../studiKasus/MyThreadClass_studikasus.py | 67 +++++++++++++++++++ .../Thread_definition_studikasus.py | 17 +++++ 4 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 Chapter02/studiKasus/Barrier_studikasus.py create mode 100644 Chapter02/studiKasus/MyThreadClass_studikasus.py create mode 100644 Chapter02/studiKasus/Thread_definition_studikasus.py diff --git a/Chapter02/Condition.py b/Chapter02/Condition.py index 828ceec..f35bc83 100644 --- a/Chapter02/Condition.py +++ b/Chapter02/Condition.py @@ -27,7 +27,7 @@ def consume(self): condition.notify() def run(self): - for i in range(20): + for i in range(5): time.sleep(2) self.consume() @@ -50,7 +50,7 @@ def produce(self): condition.notify() def run(self): - for i in range(20): + for i in range(5): time.sleep(0.5) self.produce() diff --git a/Chapter02/studiKasus/Barrier_studikasus.py b/Chapter02/studiKasus/Barrier_studikasus.py new file mode 100644 index 0000000..466a7fe --- /dev/null +++ b/Chapter02/studiKasus/Barrier_studikasus.py @@ -0,0 +1,29 @@ +from random import randrange +from threading import Barrier, Thread +from time import ctime, sleep + +jmlh_org = 3 +kota_tujuan = Barrier(jmlh_org) +orangmudik = ['Asep Gokil', 'Udin Wazowski', 'Papope Cool'] + +def mudik(): + name = orangmudik.pop() + sleep(randrange(2, 5)) # Menunggu sesuai waktu antara 2 sampai 5 detik secara random + print('%s Sampai Ke Kota pada hari: %s \n' % (name, ctime())) + kota_tujuan.wait() # Menunggu semua thread selesai + +def main(): + threads = [] + print('Mudik Dilaksanakan') + # Membuat Thread + for i in range(jmlh_org): + # Membuat thread baru untuk menjalankan function + threads.append(Thread(target=mudik)) + threads[-1].start() + # Menunggu semua thread selesai + for thread in threads: + thread.join() + print('Alhamdulillah, sampai pada tujuan dengan selamat') # Thread selesai + +if __name__ == "__main__": + main() diff --git a/Chapter02/studiKasus/MyThreadClass_studikasus.py b/Chapter02/studiKasus/MyThreadClass_studikasus.py new file mode 100644 index 0000000..45e6fff --- /dev/null +++ b/Chapter02/studiKasus/MyThreadClass_studikasus.py @@ -0,0 +1,67 @@ +import time +import os +from random import randint +from threading import Thread + +class MyThreadClass (Thread): + def __init__(self, name, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + def run(self): + print ("---> " + self.name + \ + " running, belonging to process ID "\ + + str(os.getpid()) + "\n") + time.sleep(self.duration) + print ("---> " + self.name + " over\n") + + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = MyThreadClass("Thread#1 ", randint(1,10)) + thread2 = MyThreadClass("Thread#2 ", randint(1,10)) + thread3 = MyThreadClass("Thread#3 ", randint(1,10)) + thread4 = MyThreadClass("Thread#4 ", randint(1,10)) + thread5 = MyThreadClass("Thread#5 ", randint(1,10)) + thread6 = MyThreadClass("Thread#6 ", randint(1,10)) + thread7 = MyThreadClass("Thread#7 ", randint(1,10)) + thread8 = MyThreadClass("Thread#8 ", randint(1,10)) + thread9 = MyThreadClass("Thread#9 ", randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + + +if __name__ == "__main__": + main() + + + + diff --git a/Chapter02/studiKasus/Thread_definition_studikasus.py b/Chapter02/studiKasus/Thread_definition_studikasus.py new file mode 100644 index 0000000..154f7f2 --- /dev/null +++ b/Chapter02/studiKasus/Thread_definition_studikasus.py @@ -0,0 +1,17 @@ +import threading + + +def my_func(thread_number): + return print('my_func called by thread N°{}'.format(thread_number)) + + +def main(): + threads = [] + for i in range(10): + t = threading.Thread(target=my_func, args=(i,)) + threads.append(t) + t.start() + t.join() + +if __name__ == "__main__": + main() \ No newline at end of file From 3a10616b175f08efea619eb909d75edcf1a9b224 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Wed, 20 Apr 2022 14:53:54 +0700 Subject: [PATCH 09/16] Quis Sister 1 --- .../Barrier_studikasus.py | 29 ++++++++ .../Condition_studikasus.py | 70 +++++++++++++++++++ .../Dzul Jalali Wal Ikram/Event_studikasus.py | 47 +++++++++++++ .../Dzul Jalali Wal Ikram/Lock_studikasus.py | 36 ++++++++++ .../MyThreadClass_studikasus.py | 67 ++++++++++++++++++ .../Dzul Jalali Wal Ikram/Queue_studikasus.py | 51 ++++++++++++++ .../Dzul Jalali Wal Ikram/RLock_studikasus.py | 60 ++++++++++++++++ .../Semaphore_studikasus.py | 41 +++++++++++ .../Thread_definition_studikasus.py | 24 +++++++ .../Dzul Jalali Wal Ikram/Thread_determine.py | 37 ++++++++++ 10 files changed, 462 insertions(+) create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Barrier_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Condition_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Event_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Lock_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/MyThreadClass_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Queue_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/RLock_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Semaphore_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_definition_studikasus.py create mode 100644 QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_determine.py diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Barrier_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Barrier_studikasus.py new file mode 100644 index 0000000..7ba32ce --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Barrier_studikasus.py @@ -0,0 +1,29 @@ +from random import randrange +from threading import Barrier, Thread +from time import ctime, sleep + +jmlh_org = 3 +kota_tujuan = Barrier(jmlh_org) +orangmudik = ['Asep Gokil', 'Udin Wazowski', 'Papope Cool'] + +def mudik(): + name = orangmudik.pop() + sleep(randrange(2, 5)) # Menunggu sesuai waktu antara 2 sampai 5 detik secara random + print('%s Sampai Ke Kota pada hari: %s \n' % (name, ctime())) + kota_tujuan.wait() # Menunggu semua thread selesai + +def main(): + threads = [] + print('Mudik Dilaksanakan') + # Membuat Thread + for i in range(jmlh_org): + # Membuat thread baru untuk menjalankan function + threads.append(Thread(target=mudik)) + threads[-1].start() + # Menunggu semua thread selesai + for thread in threads: + thread.join() + print('Alhamdulillah, sampai ditempat tujuan dengan selamat') # Thread selesai + +if __name__ == "__main__": + main() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Condition_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Condition_studikasus.py new file mode 100644 index 0000000..ba1a19f --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Condition_studikasus.py @@ -0,0 +1,70 @@ +import logging +import threading +import time + +LOG_FORMAT = '%(asctime)s %(threadName)-17s %(levelname)-8s %(message)s' +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) + +items = [] +condition = threading.Condition() + + +class Siswa(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def siswa(self): + + with condition: + + if len(items) == 0: + logging.info('tidak ada makanan untuk dikonsumsi') + condition.wait() + + items.pop() + logging.info('mengkonsumsi 1 makanan') + + condition.notify() + + def run(self): + for i in range(10): + time.sleep(2) + self.siswa() + + +class Kantin(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def kantin(self): + + with condition: + + if len(items) == 10: + logging.info('makanan disediakan {}. Stopped'.format(len(items))) + condition.wait() + + items.append(1) + logging.info('jumlah makanan yang disediakan {}'.format(len(items))) + + condition.notify() + + def run(self): + for i in range(10): + time.sleep(0.5) + self.kantin() + + +def main(): + kantin = Kantin(name='Kantin') + siswa = Siswa(name='Siswa') + + kantin.start() + siswa.start() + + kantin.join() + siswa.join() + + +if __name__ == "__main__": + main() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Event_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Event_studikasus.py new file mode 100644 index 0000000..5e46a0b --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Event_studikasus.py @@ -0,0 +1,47 @@ +import logging +import threading +import time +import random + +LOG_FORMAT = '%(asctime)s %(threadName)-17s %(levelname)-8s %(message)s' +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) + +items = [] +event = threading.Event() + + +class Pemain(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def run(self): + while True: + time.sleep(2) + event.wait() + item = items.pop() + logging.info('Pemain dengan nomor punggung %d masuk kedalam tim '\ + % (item)) + +class Pelatih(threading.Thread): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def run(self): + for i in range(5): + time.sleep(2) + item = random.randint(0, 30) + items.append(item) + logging.info('Pelatih memilih pemain dengan nomor punggung %d untuk masuk kedalam tim'\ + % (item)) + event.set() + event.clear() + +if __name__ == "__main__": + t1 = Pelatih() + t2 = Pemain() + + t1.start() + t2.start() + + t1.join() + t2.join() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Lock_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Lock_studikasus.py new file mode 100644 index 0000000..3995cd8 --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Lock_studikasus.py @@ -0,0 +1,36 @@ +import threading +import random +from threading import Thread +import time + + +# Lock Definition +threadLock = threading.Lock() + +class subclassThread (Thread): + def __init__(self, name): + Thread.__init__(self) + self.name = name + def run(self): + threadLock.acquire() + print(self.name, "Sedang Mengantri untuk membayar") + time.sleep(random.randint(1,10)) + print(self.name, "Selesai Mengantri") + threadLock.release() + + +def main(): + thread1 = subclassThread("Person #1 ") + thread2 = subclassThread("Person #2 ") + + thread1.start() + thread2.start() + + thread1.join() + thread2.join() + + print("End") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/MyThreadClass_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/MyThreadClass_studikasus.py new file mode 100644 index 0000000..45e6fff --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/MyThreadClass_studikasus.py @@ -0,0 +1,67 @@ +import time +import os +from random import randint +from threading import Thread + +class MyThreadClass (Thread): + def __init__(self, name, duration): + Thread.__init__(self) + self.name = name + self.duration = duration + def run(self): + print ("---> " + self.name + \ + " running, belonging to process ID "\ + + str(os.getpid()) + "\n") + time.sleep(self.duration) + print ("---> " + self.name + " over\n") + + +def main(): + start_time = time.time() + + # Thread Creation + thread1 = MyThreadClass("Thread#1 ", randint(1,10)) + thread2 = MyThreadClass("Thread#2 ", randint(1,10)) + thread3 = MyThreadClass("Thread#3 ", randint(1,10)) + thread4 = MyThreadClass("Thread#4 ", randint(1,10)) + thread5 = MyThreadClass("Thread#5 ", randint(1,10)) + thread6 = MyThreadClass("Thread#6 ", randint(1,10)) + thread7 = MyThreadClass("Thread#7 ", randint(1,10)) + thread8 = MyThreadClass("Thread#8 ", randint(1,10)) + thread9 = MyThreadClass("Thread#9 ", randint(1,10)) + + # Thread Running + thread1.start() + thread2.start() + thread3.start() + thread4.start() + thread5.start() + thread6.start() + thread7.start() + thread8.start() + thread9.start() + + # Thread joining + thread1.join() + thread2.join() + thread3.join() + thread4.join() + thread5.join() + thread6.join() + thread7.join() + thread8.join() + thread9.join() + + # End + print("End") + + #Execution Time + print("--- %s seconds ---" % (time.time() - start_time)) + + +if __name__ == "__main__": + main() + + + + diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Queue_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Queue_studikasus.py new file mode 100644 index 0000000..f85861c --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Queue_studikasus.py @@ -0,0 +1,51 @@ +from threading import Thread +from queue import Queue +import time +import random + + +class CustomerService(Thread): + + def __init__(self, queue): + Thread.__init__(self) + self.queue = queue + + def run(self): + for i in range(5): + item = random.randint(0, 20) + self.queue.put(item) + print('System memberitahu : antrian nomor %d akan mendapat giliran selanjutnya %s\n'\ + % (item, self.name)) + time.sleep(1) + + +class Costumer(Thread): + + def __init__(self, queue): + Thread.__init__(self) + self.queue = queue + + def run(self): + while True: + item = self.queue.get() + print('%d muncul dari antrian oleh %s'\ + % (item, self.name)) + self.queue.task_done() + +if __name__ == '__main__': + queue = Queue() + + t1 = CustomerService(queue) + t2 = Costumer(queue) + t3 = Costumer(queue) + t4 = Costumer(queue) + + t1.start() + t2.start() + t3.start() + t4.start() + + t1.join() + t2.join() + t3.join() + t4.join() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/RLock_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/RLock_studikasus.py new file mode 100644 index 0000000..1111487 --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/RLock_studikasus.py @@ -0,0 +1,60 @@ +import threading +import time +import random + + +class Kelas: + def __init__(self): + self.lock = threading.RLock() + self.total_items = 0 + + def execute(self, value): + with self.lock: + self.total_items += value + + def add(self): + with self.lock: + self.execute(1) + + def remove(self): + with self.lock: + self.execute(-1) + +def lapangan(box, items): + print("Murid sebanyak {} orang harus keluar kelas dan berkumpul dilapangan \n".format(items)) + while items: + box.add() + time.sleep(1) + items -= 1 + print("Satu Murid sampai dilapangan -->{} Murid yang harus ke lapangan \n".format(items)) + + + +def kelas(box, items): + print("Jumlah murid {} yang tidak berangkat ke lapangan \n".format(items)) + while items: + box.remove() + time.sleep(1) + items -= 1 + print("Murid izin tidak kelapangan -->{} Murid yang tidak ke lapangan \n".format(items)) + + +def main(): + items = 10 + box = Kelas() + + t1 = threading.Thread(target=lapangan, \ + args=(box, random.randint(10,20))) + t2 = threading.Thread(target=kelas, \ + args=(box, random.randint(1,10))) + + t1.start() + t2.start() + + + t1.join() + t2.join() + + +if __name__ == "__main__": + main() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Semaphore_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Semaphore_studikasus.py new file mode 100644 index 0000000..017d429 --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Semaphore_studikasus.py @@ -0,0 +1,41 @@ +import logging +import threading +import time +import random + +LOG_FORMAT = '%(asctime)s %(threadName)-17s %(levelname)-8s %(message)s' +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) + + +semaphore = threading.Semaphore(0) +item = 0 + + +def nasabah(): + logging.info('Nasabah Menunggu nomor Antriannya dipanggil') + semaphore.acquire() + logging.info('Nasabah dengan nomor antrian %d menuju Customer Service' % (item)) + + +def cs(): + global item + time.sleep(3) + item = random.randint(0, 100) + logging.info('Customer Service memanggil nomor antrian {}'.format(item)) + semaphore.release() + + +def main(): + for i in range(5): + t1 = threading.Thread(target=nasabah) + t2 = threading.Thread(target=cs) + + t1.start() + t2.start() + + t1.join() + t2.join() + + +if __name__ == "__main__": + main() diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_definition_studikasus.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_definition_studikasus.py new file mode 100644 index 0000000..6e32005 --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_definition_studikasus.py @@ -0,0 +1,24 @@ +from random import randint +import threading +import time + + +def waktu(thread_number): + count = 0 + while count < 5: + time.sleep(randint(0,7)) + count += 1 + return print(thread_number, "Processing", time.ctime(time.time())) + + +def main(): + threads = [] + for i in range(5): + t = threading.Thread(target=waktu, args=(i,)) + threads.append(t) + t.start() + t.join() + print("---Download Selesai---") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_determine.py b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_determine.py new file mode 100644 index 0000000..ae425e7 --- /dev/null +++ b/QUIS SISTER 1/Dzul Jalali Wal Ikram/Thread_determine.py @@ -0,0 +1,37 @@ +import threading +from time import ctime, sleep +from random import randrange + + +def task1(): + print (threading.currentThread().getName()+str('--> Memulai Tugas')) + sleep(randrange(2, 5)) + print (threading.currentThread().getName()+str( '--> Tugas Selesai')) + return + +def task2(): + print (threading.currentThread().getName()+str('--> Memulai Tugas')) + sleep(randrange(2, 5)) + print (threading.currentThread().getName()+str( '--> Tugas Selesai')) + return + +def task3(): + print (threading.currentThread().getName()+str('--> Memulai Tugas')) + sleep(randrange(2, 5)) + print (threading.currentThread().getName()+str( '--> Tugas Selesai')) + return + + +if __name__ == "__main__": + + t1 = threading.Thread(name='task1', target=task1) + t2 = threading.Thread(name='task2', target=task2) + t3 = threading.Thread(name='task3',target=task3) + + t1.start() + t2.start() + t3.start() + + t1.join() + t2.join() + t3.join() From 7ebf817de758d20f1ddd8c3795802a1655f81598 Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Tue, 14 Jun 2022 19:53:44 +0700 Subject: [PATCH 10/16] up chapter 5 --- Chapter02/Event.py | 2 +- Chapter02/studiKasus/Barrier_studikasus.py | 2 +- Chapter02/studiKasus/Queue_studikasus.py | 51 ++++++++++++ .../Thread_definition_studikasus.py | 14 +++- .../myFunc_studikasus.cpython-310.pyc | Bin 0 -> 419 bytes .../communicating_with_pipe_studikasus.py | 26 ++++++ .../communicating_with_queue_studikasus.py | 52 ++++++++++++ .../studikasus/killing_process_studikasus.py | 20 +++++ Chapter03/studikasus/myFunc_studikasus.py | 5 ++ .../studikasus/naming_process_studikasus.py | 24 ++++++ .../studikasus/process_pool_studikasus.py | 32 ++++++++ .../studikasus/spawning_process_namespace.py | 8 ++ .../studikasus/spawning_process_studikasus.py | 14 ++++ Chapter05/Praktikum/asyncio_coroutine.py | 75 ++++++++++++++++++ Chapter05/Praktikum/asyncio_event_loop.py | 49 ++++++++++++ .../Praktikum/concurrent_futures_pooling.py | 38 +++++++++ .../Praktikum/praktikum_asyncio_coroutine.py | 75 ++++++++++++++++++ .../praktikum_asyncio_event_looping.py | 45 +++++++++++ .../Praktikum/praktikum_asyncio_futures.py | 41 ++++++++++ .../praktikum_asyncio_futures_pooling.py | 39 +++++++++ Chapter05/Praktikum/test_manipulation.py | 42 ++++++++++ Chapter05/concurrent_futures_pooling.py | 1 + UTS/chapter2/test.py | 44 ++++++++++ UTS/chapter3/test2.py | 38 +++++++++ 24 files changed, 731 insertions(+), 6 deletions(-) create mode 100644 Chapter02/studiKasus/Queue_studikasus.py create mode 100644 Chapter03/studikasus/__pycache__/myFunc_studikasus.cpython-310.pyc create mode 100644 Chapter03/studikasus/communicating_with_pipe_studikasus.py create mode 100644 Chapter03/studikasus/communicating_with_queue_studikasus.py create mode 100644 Chapter03/studikasus/killing_process_studikasus.py create mode 100644 Chapter03/studikasus/myFunc_studikasus.py create mode 100644 Chapter03/studikasus/naming_process_studikasus.py create mode 100644 Chapter03/studikasus/process_pool_studikasus.py create mode 100644 Chapter03/studikasus/spawning_process_namespace.py create mode 100644 Chapter03/studikasus/spawning_process_studikasus.py create mode 100644 Chapter05/Praktikum/asyncio_coroutine.py create mode 100644 Chapter05/Praktikum/asyncio_event_loop.py create mode 100644 Chapter05/Praktikum/concurrent_futures_pooling.py create mode 100644 Chapter05/Praktikum/praktikum_asyncio_coroutine.py create mode 100644 Chapter05/Praktikum/praktikum_asyncio_event_looping.py create mode 100644 Chapter05/Praktikum/praktikum_asyncio_futures.py create mode 100644 Chapter05/Praktikum/praktikum_asyncio_futures_pooling.py create mode 100644 Chapter05/Praktikum/test_manipulation.py create mode 100644 UTS/chapter2/test.py create mode 100644 UTS/chapter3/test2.py diff --git a/Chapter02/Event.py b/Chapter02/Event.py index 4cc0eca..9c241eb 100644 --- a/Chapter02/Event.py +++ b/Chapter02/Event.py @@ -29,7 +29,7 @@ def __init__(self, *args, **kwargs): def run(self): for i in range(5): time.sleep(2) - item = random.randint(0, 100) + item = random.randint(0, 10) items.append(item) logging.info('Producer notify: item {} appended by {}'\ .format(item, self.name)) diff --git a/Chapter02/studiKasus/Barrier_studikasus.py b/Chapter02/studiKasus/Barrier_studikasus.py index 466a7fe..7ba32ce 100644 --- a/Chapter02/studiKasus/Barrier_studikasus.py +++ b/Chapter02/studiKasus/Barrier_studikasus.py @@ -23,7 +23,7 @@ def main(): # Menunggu semua thread selesai for thread in threads: thread.join() - print('Alhamdulillah, sampai pada tujuan dengan selamat') # Thread selesai + print('Alhamdulillah, sampai ditempat tujuan dengan selamat') # Thread selesai if __name__ == "__main__": main() diff --git a/Chapter02/studiKasus/Queue_studikasus.py b/Chapter02/studiKasus/Queue_studikasus.py new file mode 100644 index 0000000..f85861c --- /dev/null +++ b/Chapter02/studiKasus/Queue_studikasus.py @@ -0,0 +1,51 @@ +from threading import Thread +from queue import Queue +import time +import random + + +class CustomerService(Thread): + + def __init__(self, queue): + Thread.__init__(self) + self.queue = queue + + def run(self): + for i in range(5): + item = random.randint(0, 20) + self.queue.put(item) + print('System memberitahu : antrian nomor %d akan mendapat giliran selanjutnya %s\n'\ + % (item, self.name)) + time.sleep(1) + + +class Costumer(Thread): + + def __init__(self, queue): + Thread.__init__(self) + self.queue = queue + + def run(self): + while True: + item = self.queue.get() + print('%d muncul dari antrian oleh %s'\ + % (item, self.name)) + self.queue.task_done() + +if __name__ == '__main__': + queue = Queue() + + t1 = CustomerService(queue) + t2 = Costumer(queue) + t3 = Costumer(queue) + t4 = Costumer(queue) + + t1.start() + t2.start() + t3.start() + t4.start() + + t1.join() + t2.join() + t3.join() + t4.join() diff --git a/Chapter02/studiKasus/Thread_definition_studikasus.py b/Chapter02/studiKasus/Thread_definition_studikasus.py index 154f7f2..0024609 100644 --- a/Chapter02/studiKasus/Thread_definition_studikasus.py +++ b/Chapter02/studiKasus/Thread_definition_studikasus.py @@ -1,14 +1,20 @@ +from random import randint import threading +import time -def my_func(thread_number): - return print('my_func called by thread N°{}'.format(thread_number)) +def waktu(thread_number): + count = 0 + while count < 5: + time.sleep(randint(0,7)) + count += 1 + return print(thread_number, time.ctime(time.time())) def main(): threads = [] - for i in range(10): - t = threading.Thread(target=my_func, args=(i,)) + for i in range(5): + t = threading.Thread(target=waktu, args=(i,)) threads.append(t) t.start() t.join() diff --git a/Chapter03/studikasus/__pycache__/myFunc_studikasus.cpython-310.pyc b/Chapter03/studikasus/__pycache__/myFunc_studikasus.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8e95311c33f868beaf49ed6111e06d5610bf92bb GIT binary patch literal 419 zcmZ8du};G<5Iv_URJ4VSl?-&K1PF<(LI_kq0*R_>%7TI_H@1jr;so0nTEbL*fY0E2 z*s?P53rw6_Au7(gcY62Uoh_%$<_2JV>^_g*uzp&y8V-_EOx-|Wz{o4y0dst4S3-iV z->^Oxvx}+s5DaEN1PWHsA+c C^Jf_V literal 0 HcmV?d00001 diff --git a/Chapter03/studikasus/communicating_with_pipe_studikasus.py b/Chapter03/studikasus/communicating_with_pipe_studikasus.py new file mode 100644 index 0000000..41eeb29 --- /dev/null +++ b/Chapter03/studikasus/communicating_with_pipe_studikasus.py @@ -0,0 +1,26 @@ +import multiprocessing + +def admin(conn, events): + for event in events: + conn.send(event) + print(f"Admin mengcheck informasi: {event}") + +def user(conn): + while True: + event = conn.recv() + if event == "tolak": + print("Role user tidak di approve") + return + print(f"username: {event} diapprove menjadi Owner") + + + +if __name__ == "__main__": + events = ["udinkeren", "papopeee", "Pack Brodi the guardian of kos", "Harry Potter", "tolak"] + conn1, conn2 = multiprocessing.Pipe() + process_1 = multiprocessing.Process(target=admin, args=(conn1, events)) + process_2 = multiprocessing.Process(target=user, args=(conn2,)) + process_1.start() + process_2.start() + process_1.join() + process_2.join() \ No newline at end of file diff --git a/Chapter03/studikasus/communicating_with_queue_studikasus.py b/Chapter03/studikasus/communicating_with_queue_studikasus.py new file mode 100644 index 0000000..89e75a9 --- /dev/null +++ b/Chapter03/studikasus/communicating_with_queue_studikasus.py @@ -0,0 +1,52 @@ +import multiprocessing +import random +import time + + +class Pemilik(multiprocessing.Process): + def __init__(self, queue): + multiprocessing.Process.__init__(self) + self.queue = queue + + def run(self) : + for i in range(4): + kostrakan = random.randrange(0, 20) + self.queue.put(kostrakan) + print ("Proses Pemilik : User dengan ID %d Merequest Role sebagai Pemilik"\ + % (kostrakan)) + time.sleep(1) + print ("Jumlah User yang melakukan Request %s"\ + % self.queue.qsize()) + +class Pencari(multiprocessing.Process): + def __init__(self, queue): + multiprocessing.Process.__init__(self) + self.queue = queue + + def run(self): + while True: + if (self.queue.empty()): + print("Tidak Ada User yang request Role :(") + break + else : + time.sleep(2) + item = self.queue.get() + print ('Proses Pencari : Bangunan %d Tersedia \ + dimiliki oleh %s \n'\ + % (item, self.name)) + time.sleep(1) + + +if __name__ == '__main__': + queue = multiprocessing.Queue() + process_Pemilik = Pemilik(queue) + process_pencari = Pencari(queue) + process_Pemilik.start() + process_pencari.start() + process_Pemilik.join() + process_pencari.join() + + + + + diff --git a/Chapter03/studikasus/killing_process_studikasus.py b/Chapter03/studikasus/killing_process_studikasus.py new file mode 100644 index 0000000..978b783 --- /dev/null +++ b/Chapter03/studikasus/killing_process_studikasus.py @@ -0,0 +1,20 @@ +import multiprocessing +import time + +def startprocess(): + print ('Start') + time.sleep(0.1) + print ('Finish') + +if __name__ == '__main__': + process = multiprocessing.Process(target=startprocess) + print ('Sebelum Eksekusi:', process, process.is_alive()) + + process.start() + print ('Check saat proses Berjalan:', process, process.is_alive()) + + process.terminate() + print ('Check saat proses Dihentikan:', process, process.is_alive()) + + process.join() + print ('Proses join:', process, process.is_alive()) \ No newline at end of file diff --git a/Chapter03/studikasus/myFunc_studikasus.py b/Chapter03/studikasus/myFunc_studikasus.py new file mode 100644 index 0000000..230b4de --- /dev/null +++ b/Chapter03/studikasus/myFunc_studikasus.py @@ -0,0 +1,5 @@ +def iniFunction(i): + print ('Mengecheck user dengan Role: %s' %i) + for j in range (0,i): + print('Jumlah User :%s' %j) + return \ No newline at end of file diff --git a/Chapter03/studikasus/naming_process_studikasus.py b/Chapter03/studikasus/naming_process_studikasus.py new file mode 100644 index 0000000..3909447 --- /dev/null +++ b/Chapter03/studikasus/naming_process_studikasus.py @@ -0,0 +1,24 @@ +import multiprocessing +import time +import random + +def approveRole(): + name = multiprocessing.current_process().name + userId = random.randrange(0, 20) + print ("Admin mulai melakukan = %s \n" %name) + time.sleep(3) + print ("Admin selesai mengapprove Role Request user dengan ID %s sebagai Owner \n" %userId) + +if __name__ == '__main__': + process_with_name = multiprocessing.Process\ + (name='Approve Role User',\ + target=approveRole) + + process_with_default_name = multiprocessing.Process\ + (target=approveRole) + + process_with_name.start() + process_with_default_name.start() + + process_with_name.join() + process_with_default_name.join() \ No newline at end of file diff --git a/Chapter03/studikasus/process_pool_studikasus.py b/Chapter03/studikasus/process_pool_studikasus.py new file mode 100644 index 0000000..2c685a4 --- /dev/null +++ b/Chapter03/studikasus/process_pool_studikasus.py @@ -0,0 +1,32 @@ +#Using a Process Pool – Chapter 3: Process Based Parallelism +import multiprocessing +from time import ctime, sleep +import random +import time + +def test(data): + result = data*data + return result + +bangunan1 = 'Kos' +bangunan2 = 'Kontrakan' +nama = ['Pack Udien', 'Bu Marinie'] + +if __name__ == '__main__': + inputs1 = list(range(9,10)) + inputs2 = list(range(19,20)) + + pool = multiprocessing.Pool(processes=4) + pool_outputs1 = pool.map(test, inputs1) + pool_outputs2 = pool.map(test, inputs2) + + pencari1 = bangunan1 + pencari2 = bangunan2 + + time.sleep(random.randrange(0, 10)) + print (f'Pencarian Tempat Hidup Sementara: \n Jenis Bangunan: %s \n Nomor Bangunan: %s \n Tanggal: %s \n' % (pencari1, pool_outputs1, ctime())) + print (f'Pencarian Tempat Hidup Sementara: \n Jenis Bangunan: %s \n Nomor Bangunan: %s \n Tanggal: %s \n' % (pencari2, pool_outputs2, ctime())) + + pool.close() + pool.join() + print('Selesai') \ No newline at end of file diff --git a/Chapter03/studikasus/spawning_process_namespace.py b/Chapter03/studikasus/spawning_process_namespace.py new file mode 100644 index 0000000..1710b40 --- /dev/null +++ b/Chapter03/studikasus/spawning_process_namespace.py @@ -0,0 +1,8 @@ +import multiprocessing +from myFunc_studikasus import iniFunction + +if __name__ == '__main__': + for i in range(5): + process = multiprocessing.Process(target=iniFunction, args=(i,)) + process.start() + process.join() \ No newline at end of file diff --git a/Chapter03/studikasus/spawning_process_studikasus.py b/Chapter03/studikasus/spawning_process_studikasus.py new file mode 100644 index 0000000..ef7f475 --- /dev/null +++ b/Chapter03/studikasus/spawning_process_studikasus.py @@ -0,0 +1,14 @@ +#Spawn a Process – Chapter 3: Process Based Parallelism +import multiprocessing + +def inifunction(i): + print ('Mengecheck user dengan Role: %s' %i) + for j in range (0,i): + print('Jumlah User :%s' %j) + return + +if __name__ == '__main__': + for i in range(5): + process = multiprocessing.Process(target=inifunction, args=(i,)) + process.start() + process.join() \ No newline at end of file diff --git a/Chapter05/Praktikum/asyncio_coroutine.py b/Chapter05/Praktikum/asyncio_coroutine.py new file mode 100644 index 0000000..aaab37b --- /dev/null +++ b/Chapter05/Praktikum/asyncio_coroutine.py @@ -0,0 +1,75 @@ +import asyncio +import time +from random import randint + + +@asyncio.coroutine +def memulai_aktivitas(): + print('Mendatangi toko buku\n') + input_value = randint(0, 1) + time.sleep(1) + + if input_value == 0: + result = yield from aktivitas_2(input_value) + else: + result = yield from aktivitas_1(input_value) + + print('Memulai aktivitas dengan ' + result) + + +@asyncio.coroutine +def aktivitas_1(transition_value): + output_value = 'Memilih buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_3(input_value) + else: + result = yield from aktivitas_2(input_value) + + return output_value + 'Aktivitas 1 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def aktivitas_2(transition_value): + output_value = 'Mengecek buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_1(input_value) + else: + result = yield from aktivitas_3(input_value) + + return output_value + 'Aktivitas 2 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def aktivitas_3(transition_value): + output_value = 'Membeli buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_1(input_value) + else: + result = yield from mengakhiri_aktivitas(input_value) + + return output_value + 'Aktivitas 3 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def mengakhiri_aktivitas(transition_value): + output_value = 'Membawa buku dengan transition value = %s\n' % transition_value + print('...aktivitas berhenti...') + return output_value + + +if __name__ == '__main__': + print('Finite State Machine simulation with Asyncio Coroutine') + loop = asyncio.get_event_loop() + loop.run_until_complete(memulai_aktivitas()) diff --git a/Chapter05/Praktikum/asyncio_event_loop.py b/Chapter05/Praktikum/asyncio_event_loop.py new file mode 100644 index 0000000..4d7db88 --- /dev/null +++ b/Chapter05/Praktikum/asyncio_event_loop.py @@ -0,0 +1,49 @@ +import asyncio +import time +import random + +print("Mengecek Ketersediaan Buku") + +def buku_A(end_time, loop): + print ("Buku A") + print ("Mengecek ketersediaan Buku A") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_B, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + +def buku_B(end_time, loop): + print ("Buku B") + print ("Mengecek ketersediaan Buku B") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_C, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + +def buku_C(end_time, loop): + print ("Buku C") + print ("Mengecek ketersediaan Buku B") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_A, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + + +loop = asyncio.get_event_loop() +end_loop = loop.time() + 30 +loop.call_soon(buku_A, end_loop, loop) +loop.run_forever() +loop.close() + diff --git a/Chapter05/Praktikum/concurrent_futures_pooling.py b/Chapter05/Praktikum/concurrent_futures_pooling.py new file mode 100644 index 0000000..8fb488a --- /dev/null +++ b/Chapter05/Praktikum/concurrent_futures_pooling.py @@ -0,0 +1,38 @@ +import concurrent.futures +import time + +jumlah_buku = list(range(1, 5)) + + +def menghitung(number): + for i in range(50000): + i += 1 + return i*number + + +def menilai(item): + result_item = menghitung(item) + print('Jika anda membeli %s buku, harganya %s' % (item, result_item)) + +if __name__ == '__main__': + # Sequential Execution + start_time = time.process_time() + for item in jumlah_buku: + menilai(item) + print('Waktu eksekusi Sequential dalam %s detik' % (time.process_time() - start_time)) + + + # Thread Pool Execution + start_time = time.process_time() + with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: + for item in jumlah_buku: + executor.submit(menilai, item) + print('Waktu eksekusi Thread Pool dalam %s detik' % (time.process_time() - start_time)) + + + # Process Pool Execution + start_time = time.process_time() + with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor: + for item in jumlah_buku: + executor.submit(menilai, item) + print('Waktu eksekusi Process Pool dalam %s detik' % (time.process_time() - start_time)) diff --git a/Chapter05/Praktikum/praktikum_asyncio_coroutine.py b/Chapter05/Praktikum/praktikum_asyncio_coroutine.py new file mode 100644 index 0000000..7566f2d --- /dev/null +++ b/Chapter05/Praktikum/praktikum_asyncio_coroutine.py @@ -0,0 +1,75 @@ +import asyncio +import time +from random import randint + + +@asyncio.coroutine +def start_state(): + print('Memulai Tahapan awal\n') + input_value = randint(0, 1) + time.sleep(1) + + if input_value == 0: + result = yield from tahap2(input_value) + else: + result = yield from tahap1(input_value) + + print('Mencoba Coroutine : \nStart State menuju ' + result) + + +@asyncio.coroutine +def tahap1(transition_value): + output_value = 'Tahap 1 dengan value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...Mengevaluasi Tahapan...') + if input_value == 0: + result = yield from tahap3(input_value) + else: + result = yield from tahap2(input_value) + + return output_value + 'Tahap 1 menuju %s' % result + + +@asyncio.coroutine +def tahap2(transition_value): + output_value = 'Tahap 2 dengan value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...Mengevaluasi Tahapan...') + if input_value == 0: + result = yield from tahap1(input_value) + else: + result = yield from tahap3(input_value) + + return output_value + 'Tahap 2 menuju %s' % result + + +@asyncio.coroutine +def tahap3(transition_value): + output_value = 'Tahap 3 dengan value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...Mengevaluasi Tahapan...') + if input_value == 0: + result = yield from tahap1(input_value) + else: + result = yield from end_state(input_value) + + return output_value + 'Tahap 3 menuju %s' % result + + +@asyncio.coroutine +def end_state(transition_value): + output_value = 'Tahap akhir value = %s\n' % transition_value + print('...stop computation...') + return output_value + + +if __name__ == '__main__': + print('Finite state Machine simulation with Asyncio Coroutine') + loop = asyncio.get_event_loop() + loop.run_until_complete(start_state()) diff --git a/Chapter05/Praktikum/praktikum_asyncio_event_looping.py b/Chapter05/Praktikum/praktikum_asyncio_event_looping.py new file mode 100644 index 0000000..6cc1f8b --- /dev/null +++ b/Chapter05/Praktikum/praktikum_asyncio_event_looping.py @@ -0,0 +1,45 @@ +import asyncio +import time +import random + +def task_A(end_time, loop): + print ("task_A dijalankan") + start_time = time.time() + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + print('Proses tidak memenuhi kebutuhan, melanjutkan ke proses selanjutnya', (loop.time() + 1.0) < end_time) + loop.call_later(1, task_B, end_time, loop) + else: + print('Proses memenuhi kebutuhan, menghentikan proses', (loop.time() + 1.0) < end_time) + loop.stop() + +def task_B(end_time, loop): + print ("task_B dijalankan ") + start_time = time.time() + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + print('Proses tidak memenuhi kebutuhan, melanjutkan ke proses selanjutnya', (loop.time() + 1.0) < end_time) + loop.call_later(1, task_C, end_time, loop) + else: + print('Proses memenuhi kebutuhan, menghentikan proses', (loop.time() + 1.0) < end_time) + loop.stop() + +def task_C(end_time, loop): + print ("task_C dijalankan") + start_time = time.time() + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + print('Proses tidak memenuhi kebutuhan, melanjutkan ke proses selanjutnya', (loop.time() + 1.0) < end_time) + loop.call_later(1, task_A, end_time, loop) + else: + print('Proses memenuhi kebutuhan, melanjutkan ke proses selanjutnya', (loop.time() + 1.0) < end_time) + print('Proses Dihentikan') + loop.stop() + + +loop = asyncio.get_event_loop() +end_loop = loop.time() + 60 +loop.call_soon(task_A, end_loop, loop) +loop.run_forever() +loop.close() + diff --git a/Chapter05/Praktikum/praktikum_asyncio_futures.py b/Chapter05/Praktikum/praktikum_asyncio_futures.py new file mode 100644 index 0000000..debbfe8 --- /dev/null +++ b/Chapter05/Praktikum/praktikum_asyncio_futures.py @@ -0,0 +1,41 @@ +import asyncio +import sys + + +@asyncio.coroutine +def first_coroutine(future, num): + count = 0 + for i in range(1, num + 1): + count += 1 + yield from asyncio.sleep(4) + future.set_result('First coroutine (sum of N ints) result = %s' % count) + + +@asyncio.coroutine +def second_coroutine(future, num): + count = 1 + for i in range(2, num + 1): + count *= i + yield from asyncio.sleep(4) + future.set_result('Second coroutine (factorial) result = %s' % count) + + +def got_result(future): + print(future.result()) + +if __name__ == '__main__': + num1 = int(sys.argv[1]) + num2 = int(sys.argv[2]) + + loop = asyncio.get_event_loop() + future1 = asyncio.Future() + future2 = asyncio.Future() + + tasks = [first_coroutine(future1, num1), + second_coroutine(future2, num2)] + + future1.add_done_callback(got_result) + future2.add_done_callback(got_result) + + loop.run_until_complete(asyncio.wait(tasks)) + loop.close() \ No newline at end of file diff --git a/Chapter05/Praktikum/praktikum_asyncio_futures_pooling.py b/Chapter05/Praktikum/praktikum_asyncio_futures_pooling.py new file mode 100644 index 0000000..8f23bed --- /dev/null +++ b/Chapter05/Praktikum/praktikum_asyncio_futures_pooling.py @@ -0,0 +1,39 @@ +import concurrent.futures +import time +time.clock = time.time + +number_list = list(range(1, 5)) + + +def count(number): + for i in range(9999): + i += 1 + return i*number + + +def evaluate(item): + result_item = count(item) + print('Item %s, result %s' % (item, result_item)) + +if __name__ == '__main__': + # Sequential Execution + start_time = time.clock() + for item in number_list: + evaluate(item) + print('Sequential Execution in %s seconds' % (time.clock() - start_time)) + + + # Thread Pool Execution + start_time = time.clock() + with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: + for item in number_list: + executor.submit(evaluate, item) + print('Thread Pool Execution in %s seconds' % (time.clock() - start_time)) + + + # Process Pool Execution + start_time = time.clock() + with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor: + for item in number_list: + executor.submit(evaluate, item) + print('Process Pool Execution in %s seconds' % (time.clock() - start_time)) diff --git a/Chapter05/Praktikum/test_manipulation.py b/Chapter05/Praktikum/test_manipulation.py new file mode 100644 index 0000000..fc67107 --- /dev/null +++ b/Chapter05/Praktikum/test_manipulation.py @@ -0,0 +1,42 @@ +"""Asyncio using Asyncio.Task to execute three math functions in parallel""" + +import asyncio + + +@asyncio.coroutine +def factorial(number): + fact = 1 + for i in range(2, number + 1): + print('Asyncio.Task: Compute factorial(%s)' % i) + yield from asyncio.sleep(1) + fact *= i + print('Asyncio.Task - factorial(%s) = %s' % (number, fact)) + + +@asyncio.coroutine +def fibonacci(number): + a, b = 0, 1 + for i in range(number): + print('Asyncio.Task: Compute fibonacci(%s)' % i) + yield from asyncio.sleep(1) + a, b = b, a + b + print('Asyncio.Task - fibonacci(%s) = %s' % (number, a)) + + +@asyncio.coroutine +def binomial_coefficient(n, k): + result = 1 + for i in range(1, k + 1): + result = result*(n - i + 1)/i + print('Asyncio.Task: Compute binomial_coefficient(%s)' % i) + yield from asyncio.sleep(1) + print('Asyncio.Task - binomial_coefficient(%s, %s) = %s' % (n, k, result)) + + +if __name__ == '__main__': + task_list = [asyncio.Task(factorial(5)), + asyncio.Task(fibonacci(5)), + asyncio.Task(binomial_coefficient(10, 5))] + loop = asyncio.get_event_loop() + loop.run_until_complete(asyncio.wait(task_list)) + loop.close() diff --git a/Chapter05/concurrent_futures_pooling.py b/Chapter05/concurrent_futures_pooling.py index 1074723..075b7bc 100644 --- a/Chapter05/concurrent_futures_pooling.py +++ b/Chapter05/concurrent_futures_pooling.py @@ -1,5 +1,6 @@ import concurrent.futures import time +time.clock = time.time number_list = list(range(1, 11)) diff --git a/UTS/chapter2/test.py b/UTS/chapter2/test.py new file mode 100644 index 0000000..e13cb01 --- /dev/null +++ b/UTS/chapter2/test.py @@ -0,0 +1,44 @@ +#Dzul Jalali Wal Ikram + +from random import randrange +import threading +from time import ctime, sleep +from threading import Barrier, Thread + +num_siswa = 3 +threadsynchronizer = threading.Barrier(num_siswa) +nama_siswa = ['Udin', 'Asep', 'Cecep'] + +def skip(n): + name = nama_siswa.pop() + sleep(randrange(2, 5)) + print("{} tidak hadir pada hari {} dikarenakan Sakit".format(name, ctime())) + threadsynchronizer.wait() + print("{} Surat Sakit sampai pada: {} ".format(name, ctime())) + +def total(test=None): + print("Jumlah siswa yang sakit pada hari {} adalah {} orang".format(ctime(), test)) + +def main(): + threads = [] + print('Saatnya Absen') + for i in range(num_siswa): + threads.append(Thread(target=skip, name="skip", args=(num_siswa,), group=None, kwargs=None)) + threads[-1].start() + for thread in threads: + thread.join() + print('Absen Selesai!') + + +# dict2 = {'name': 'Udin'} +my_dict = {'test': num_siswa} + +thread2 = threading.Thread(target=total,name="total", group=None, kwargs=my_dict) + +thread2.start() + +thread2.join() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/UTS/chapter3/test2.py b/UTS/chapter3/test2.py new file mode 100644 index 0000000..01e389e --- /dev/null +++ b/UTS/chapter3/test2.py @@ -0,0 +1,38 @@ +#Dzul Jalali Wal Ikram + +import multiprocessing +from multiprocessing import Barrier, Lock, Process +from time import time +from datetime import datetime + + +def barengan(synchronizer, serializer): + name = multiprocessing.current_process().name + synchronizer.wait() + now = time() + with serializer: + print("%s sampai dikelas pada tanggal %s" \ + %(name,datetime.fromtimestamp(now))) + +def sendirian(): + name = multiprocessing.current_process().name + now = time() + print("%s sampai dikelas pada tanggal %s" \ + %(name ,datetime.fromtimestamp(now))) + +if __name__ == '__main__': + synchronizer = Barrier(2) + serializer = Lock() + Process(name='Udin'\ + ,target=barengan,\ + args=(synchronizer,serializer)).start() + Process(name='Asep'\ + ,target=barengan,\ + args=(synchronizer,serializer)).start() + Process(name='Cecep'\ + ,target=sendirian).start() + Process(name='Ucup'\ + ,target=sendirian).start() + + + From ff0cb219e50521e1c13a680feed1c4092cf2fdc5 Mon Sep 17 00:00:00 2001 From: BurhanudinZuhri <59348932+burhanudinzuhri@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:47:10 +0700 Subject: [PATCH 11/16] Create Studi Kasus --- Chapter05/Studi Kasus | 1 + 1 file changed, 1 insertion(+) create mode 100644 Chapter05/Studi Kasus diff --git a/Chapter05/Studi Kasus b/Chapter05/Studi Kasus new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Chapter05/Studi Kasus @@ -0,0 +1 @@ + From bf7963f2e9ee47df470ce0db52ec3fa34ffffd2e Mon Sep 17 00:00:00 2001 From: BurhanudinZuhri <59348932+burhanudinzuhri@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:47:35 +0700 Subject: [PATCH 12/16] Delete Studi Kasus --- Chapter05/Studi Kasus | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Chapter05/Studi Kasus diff --git a/Chapter05/Studi Kasus b/Chapter05/Studi Kasus deleted file mode 100644 index 8b13789..0000000 --- a/Chapter05/Studi Kasus +++ /dev/null @@ -1 +0,0 @@ - From d39fe6c245840dceb54222b86dd75125a92b5386 Mon Sep 17 00:00:00 2001 From: burhanudinzuhri Date: Tue, 14 Jun 2022 20:52:15 +0700 Subject: [PATCH 13/16] Update Studi Kasus --- Chapter05/Studi Kasus/asyncio_and_futures.py | 41 ++++++++++ Chapter05/Studi Kasus/asyncio_coroutine.py | 75 +++++++++++++++++++ Chapter05/Studi Kasus/asyncio_event_loop.py | 49 ++++++++++++ .../Studi Kasus/asyncio_task_manipulation.py | 42 +++++++++++ .../Studi Kasus/concurrent_futures_pooling.py | 36 +++++++++ 5 files changed, 243 insertions(+) create mode 100644 Chapter05/Studi Kasus/asyncio_and_futures.py create mode 100644 Chapter05/Studi Kasus/asyncio_coroutine.py create mode 100644 Chapter05/Studi Kasus/asyncio_event_loop.py create mode 100644 Chapter05/Studi Kasus/asyncio_task_manipulation.py create mode 100644 Chapter05/Studi Kasus/concurrent_futures_pooling.py diff --git a/Chapter05/Studi Kasus/asyncio_and_futures.py b/Chapter05/Studi Kasus/asyncio_and_futures.py new file mode 100644 index 0000000..bf7f2b4 --- /dev/null +++ b/Chapter05/Studi Kasus/asyncio_and_futures.py @@ -0,0 +1,41 @@ +import asyncio +import sys + + +@asyncio.coroutine +def first_coroutine(future, num): + count = 0 + for i in range(1, num + 1): + count += 1 + yield from asyncio.sleep(4) + future.set_result('First coroutine (sum of N ints) result = %s' % count) + + +@asyncio.coroutine +def second_coroutine(future, num): + count = 1 + for i in range(2, num + 1): + count *= i + yield from asyncio.sleep(4) + future.set_result('Second coroutine (factorial) result = %s' % count) + + +def got_result(future): + print(future.result()) + +if __name__ == '__main__': + num1 = int(len(sys.argv[0])) + num2 = int(len(sys.argv[0])) + + loop = asyncio.get_event_loop() + future1 = asyncio.Future() + future2 = asyncio.Future() + + tasks = [first_coroutine(future1, num1), + second_coroutine(future2, num2)] + + future1.add_done_callback(got_result) + future2.add_done_callback(got_result) + + loop.run_until_complete(asyncio.wait(tasks)) + loop.close() \ No newline at end of file diff --git a/Chapter05/Studi Kasus/asyncio_coroutine.py b/Chapter05/Studi Kasus/asyncio_coroutine.py new file mode 100644 index 0000000..25d56a2 --- /dev/null +++ b/Chapter05/Studi Kasus/asyncio_coroutine.py @@ -0,0 +1,75 @@ +import asyncio +import time +from random import randint + + +@asyncio.coroutine +def memulai_aktivitas(): + print('Mendatangi toko buku\n') + input_value = randint(0, 1) + time.sleep(1) + + if input_value == 0: + result = yield from aktivitas_2(input_value) + else: + result = yield from aktivitas_1(input_value) + + print('Memulai aktivitas dengan ' + result) + + +@asyncio.coroutine +def aktivitas_1(transition_value): + output_value = 'Memilih buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_3(input_value) + else: + result = yield from aktivitas_2(input_value) + + return output_value + 'Aktivitas 1 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def aktivitas_2(transition_value): + output_value = 'Mengecek buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_1(input_value) + else: + result = yield from aktivitas_3(input_value) + + return output_value + 'Aktivitas 2 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def aktivitas_3(transition_value): + output_value = 'Membeli buku dengan transition value = %s\n' % transition_value + input_value = randint(0, 1) + time.sleep(1) + + print('...mengevaluasi...') + if input_value == 0: + result = yield from aktivitas_1(input_value) + else: + result = yield from mengakhiri_aktivitas(input_value) + + return output_value + 'Aktivitas 3 dilanjutkan dengan %s' % result + + +@asyncio.coroutine +def mengakhiri_aktivitas(transition_value): + output_value = 'Membawa buku dengan transition value = %s\n' % transition_value + print('...menghentikan evaluasi...') + return output_value + + +if __name__ == '__main__': + print('Finite State Machine simulation with Asyncio Coroutine') + loop = asyncio.get_event_loop() + loop.run_until_complete(memulai_aktivitas()) diff --git a/Chapter05/Studi Kasus/asyncio_event_loop.py b/Chapter05/Studi Kasus/asyncio_event_loop.py new file mode 100644 index 0000000..4d7db88 --- /dev/null +++ b/Chapter05/Studi Kasus/asyncio_event_loop.py @@ -0,0 +1,49 @@ +import asyncio +import time +import random + +print("Mengecek Ketersediaan Buku") + +def buku_A(end_time, loop): + print ("Buku A") + print ("Mengecek ketersediaan Buku A") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_B, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + +def buku_B(end_time, loop): + print ("Buku B") + print ("Mengecek ketersediaan Buku B") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_C, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + +def buku_C(end_time, loop): + print ("Buku C") + print ("Mengecek ketersediaan Buku B") + time.sleep(random.randint(0, 5)) + if (loop.time() + 1.0) < end_time: + loop.call_later(1, buku_A, end_time, loop) + print("Buku kosong, lanjut mengecek buku lainnya") + else: + print("Buku tersedia dan dapat dijual") + print(end_time) + loop.stop() + + +loop = asyncio.get_event_loop() +end_loop = loop.time() + 30 +loop.call_soon(buku_A, end_loop, loop) +loop.run_forever() +loop.close() + diff --git a/Chapter05/Studi Kasus/asyncio_task_manipulation.py b/Chapter05/Studi Kasus/asyncio_task_manipulation.py new file mode 100644 index 0000000..8f31013 --- /dev/null +++ b/Chapter05/Studi Kasus/asyncio_task_manipulation.py @@ -0,0 +1,42 @@ +"""Asyncio using Asyncio.Task to execute three math functions in parallel""" + +import asyncio + + +@asyncio.coroutine +def factorial(number): + fact = 1 + for i in range(2, number + 1): + print('Asyncio.Task: Compute factorial(%s)' % i) + yield from asyncio.sleep(1) + fact *= i + print('Asyncio.Task - factorial(%s) = %s' % (number, fact)) + + +@asyncio.coroutine +def fibonacci(number): + a, b = 0, 1 + for i in range(number): + print('Asyncio.Task: Compute fibonacci(%s)' % i) + yield from asyncio.sleep(1) + a, b = b, a + b + print('Asyncio.Task - fibonacci(%s) = %s' % (number, a)) + + +@asyncio.coroutine +def binomial_coefficient(n, k): + result = 1 + for i in range(1, k + 1): + result = result*(n - i + 1)/i + print('Asyncio.Task: Compute binomial_coefficient(%s)' % i) + yield from asyncio.sleep(1) + print('Asyncio.Task - binomial_coefficient(%s, %s) = %s' % (n, k, result)) + + +if __name__ == '__main__': + task_list = [asyncio.Task(factorial(10)), + asyncio.Task(fibonacci(10)), + asyncio.Task(binomial_coefficient(20, 10))] + loop = asyncio.get_event_loop() + loop.run_until_complete(asyncio.wait(task_list)) + loop.close() diff --git a/Chapter05/Studi Kasus/concurrent_futures_pooling.py b/Chapter05/Studi Kasus/concurrent_futures_pooling.py new file mode 100644 index 0000000..0228a2e --- /dev/null +++ b/Chapter05/Studi Kasus/concurrent_futures_pooling.py @@ -0,0 +1,36 @@ +import concurrent.futures +import time + +jumlah_buku = list(range(1, 5)) + +def menghitung(number): + for i in range(0,50000): + i += 1 + return i*number + +def menilai(item): + result_item = menghitung(item) + print('Jika anda membeli %s buku, harganya %s' % (item, result_item)) + +if __name__ == '__main__': + # Sequential Execution + start_time = time.process_time() + for item in jumlah_buku: + menilai(item) + print('Waktu yang dibutuhkan untuk eksekusi Sequential yaitu %s detik' % (time.process_time() - start_time)) + + + # Thread Pool Execution + start_time = time.process_time() + with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: + for item in jumlah_buku: + executor.submit(menilai, item) + print('Waktu yang dibutuhkan untuk eksekusi Thread Pool yaitu %s detik' % (time.process_time() - start_time)) + + + # Process Pool Execution + start_time = time.process_time() + with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor: + for item in jumlah_buku: + executor.submit(menilai, item) + print('Waktu yang dibutuhkan untuk eksekusi Process Pool yaitu %s detik' % (time.process_time() - start_time)) From c98c2d3157973f435d99a1e44fa0813e9260993e Mon Sep 17 00:00:00 2001 From: DzulJalali Date: Tue, 21 Jun 2022 21:44:36 +0700 Subject: [PATCH 14/16] studkikasus chapter 6 --- .../Celery/__pycache__/addTask.cpython-310.pyc | Bin 0 -> 409 bytes .../praktikum/__pycache__/tugas.cpython-310.pyc | Bin 0 -> 529 bytes Chapter06/Celery/praktikum/tugas.py | 11 +++++++++++ Chapter06/Celery/praktikum/tugas_jalan.py | 12 ++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 Chapter06/Celery/__pycache__/addTask.cpython-310.pyc create mode 100644 Chapter06/Celery/praktikum/__pycache__/tugas.cpython-310.pyc create mode 100644 Chapter06/Celery/praktikum/tugas.py create mode 100644 Chapter06/Celery/praktikum/tugas_jalan.py diff --git a/Chapter06/Celery/__pycache__/addTask.cpython-310.pyc b/Chapter06/Celery/__pycache__/addTask.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f6c7290367a535a006650fdea42c2150661c7979 GIT binary patch literal 409 zcmZ8cu};G<6!de_G@zChM%Exfm>4RAiYf+{QqfLUByeMkmO8buU5QlPU_*QeBOkzz zWM$$Pn6T4IAf9y3cYe?Eoou(ak*lkh_wk22KfU-{p%YyPbKn|73CGkO9NvgQya@t5022~<&!3$DwmNf{eaGh6P_;z4!N^lrh8?FyMwF_Ffm zX#yk~YdPaO$NurAJoo51nAo)yTEQ-Ie?b2YCAfme3QFyb*6sV2cd~P(#5AXND(5B} zly)NLhXbmq=HkXojpfDuh-<^gRR13jFNdRx>#R4S%5r^tlC1+|8~;bDtOCckydCc= x#@f5;Ck+zibyn@KNkEk%p>>h#`LDq>Yr35(J}o3$2z~}m)!|xU3x{|IegKVoV5I;6 literal 0 HcmV?d00001 diff --git a/Chapter06/Celery/praktikum/__pycache__/tugas.cpython-310.pyc b/Chapter06/Celery/praktikum/__pycache__/tugas.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b9f1375ad97e54f4545536a09d4540d48ff9610f GIT binary patch literal 529 zcmZ8dJx?1!5Z&4P-~={J3Q`)nD-xp=6bMBiiz1C>#Z;%0(AvB5ZM^4OcK0M~xq~)8 zARQ@F@^`kS;xD9u*&_wYNb`2y?2P8kH2wZAK|B2QID5hODUkOTBRNO6Ul2Iqphyh` zK!~ZL1r@*}9`ocUEg}*9hEgTRW z9*;NuZrXs$x>Za*C)l|8@RoBzv1(vZmSr-Je4>q9IUhS&3!hjegwCmlTMz3$#Dp{b ztu9Z?3$2x$GbfvsEhlSNHLFh(W|$G`+Dhw0J-8CaiWxKie^0+nuP(orql#%K%<)P2 zc9T*YwsdmY)@7&cvtIk2YF3M& Date: Tue, 21 Jun 2022 23:23:36 +0700 Subject: [PATCH 15/16] Update chapter 6 --- .../StudiKasus/FirstExample/pyro_client.py | 13 +++++++++ .../StudiKasus/FirstExample/pyro_server.py | 25 ++++++++++++++++++ .../__pycache__/chainTopology.cpython-310.pyc | Bin 0 -> 1112 bytes .../__pycache__/chainTopology.cpython-35.pyc | Bin 0 -> 1096 bytes .../StudiKasus/SecondExample/chainTopology.py | 21 +++++++++++++++ .../StudiKasus/SecondExample/client_chain.py | 5 ++++ .../StudiKasus/SecondExample/desktop.ini | 2 ++ .../SecondExample/server_chain_1.py | 18 +++++++++++++ .../SecondExample/server_chain_2.py | 18 +++++++++++++ .../SecondExample/server_chain_3.py | 18 +++++++++++++ 10 files changed, 120 insertions(+) create mode 100644 Chapter06/Pyro4/StudiKasus/FirstExample/pyro_client.py create mode 100644 Chapter06/Pyro4/StudiKasus/FirstExample/pyro_server.py create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-310.pyc create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-35.pyc create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/chainTopology.py create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/client_chain.py create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/desktop.ini create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/server_chain_1.py create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/server_chain_2.py create mode 100644 Chapter06/Pyro4/StudiKasus/SecondExample/server_chain_3.py diff --git a/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_client.py b/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_client.py new file mode 100644 index 0000000..5f05483 --- /dev/null +++ b/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_client.py @@ -0,0 +1,13 @@ +import Pyro4 + +#uri = input("insert the PYRO4 server URI (help : PYRONAME:server) ").strip() +name = input("Siapa nama anda? ").strip() +npm = input("Berapa npm anda? ").strip() +major = input("Jurusan apakah anda? ").strip() +# use name server object lookup uri shortcut +server = Pyro4.Proxy("PYRONAME:server") +print(server.welcomeMessage(name, npm, major)) + + + + diff --git a/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_server.py b/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_server.py new file mode 100644 index 0000000..cdf7ce8 --- /dev/null +++ b/Chapter06/Pyro4/StudiKasus/FirstExample/pyro_server.py @@ -0,0 +1,25 @@ +import Pyro4 + +class Server(object): + @Pyro4.expose + def welcomeMessage(self, name, npm, major): + return ("Halo selamat datang " + str(name) + " \ndengan npm " + str(npm) + " \ndari jurusan " + str(major)) + +def startServer(): + server = Server() + # make a Pyro daemon + daemon = Pyro4.Daemon() + # locate the name server running + ns = Pyro4.locateNS() + # register the server as a Pyro object + uri = daemon.register(server) + # register the object with a name in the name server + ns.register("server", uri) + # print the uri so we can use it in the client later + print("Server siap. Object uri =", uri) + # start the event loop of the server to wait for calls + daemon.requestLoop() + +if __name__ == "__main__": + startServer() + diff --git a/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-310.pyc b/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..456ddb2b5d4573f0b91758ec9f08b604c7873a02 GIT binary patch literal 1112 zcmah|Pixdb6rY*=+3m8eP)d6dOa+BKw0O`8Rix4u5$U?Ly|^rfX=b|3Hk-tmq;x|( zwI9Oc_UO?M;un~!C&5qP$@h}2Y(a1!Z{Ey%^Lzh(NfsAd1lIRo-%h?*g#5t6{Bq#1 z1D}2fLJ&bC(kGIP=o=!Ku&#-)B)hV%Xx|d_h;;0q;77Uv%K63MumhjI4?>bY6{ODu z73`Y8OH0_W+rj|^*EqXpJd6WK=kG!tA$H-@s~}2R5}%X|BtU^=g1}?i?O4W+`B<9e zAXiGpnXjd~kgAJ!OLyR_2Hns-6Np_aR8$GVL zl97M(_UL&3a1hiUPqqd+%SCw3b*=~LL?urLS_Vlh>8mFfr8E$PnfQ78_6a?v&N`l1>|VcLTn#lWDW0H}o?r*>piT z!bKazU|?m?@mj-Xs0OOJzI^RXFCc zHnAH3cYI3fDCA{RJlH%1D=npC^WBF6JeIC zJVq~p&u5u+S``(H)5A#`J4lp-gGw$Z%7%v(Ta1&cFwTt2Q>a3iMyiqkYA|jX15Vbl z6i(GNW`!A7Nu5VoMXy>k5$hfZ`~&q0Ds%-nuteK*g|$I0Q=1lxH6v#D-HwCgL5BOj zY5D#*5qX4q+xI`^JgO~f;TC)@ATnE3QIS>1riyt@(qwH%;a$g8n2d4dWtwPd+~i~= XgRHXs3&=EI*709qM`vg@Tcv*hNbVLH literal 0 HcmV?d00001 diff --git a/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-35.pyc b/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fa4ade083b42d6d75797bd0482f4fa7db32ee640 GIT binary patch literal 1096 zcmZuv&2AGh5FYPe(kN}AMXiL8Y7R&Qq;la@5EM$)6QQDTXtZdxc%5|9&3dsnw28{8 zybN~^Jd3ZKcm+<(cvGpB@Y=Iu&-fe9H?y(4-1)Ws@>A>s{Dx~IM12>Rd4eLt$)Erj z07!r_gM-Y2%!lu2@IiWT>BA+1flq!%z2FaCg1#VmH9S;yahZoG5M;mzc7QObc!Wf^ zaRyEgAPW&Gvf1CH&?q zF6Hejv!Hxw(3=8WF880PV47oBozphx$51mEdoXrIAX5OFSd;}jxDSb}(+Ko2)De+R zP9bcd6GP^k-R1}@NakR1&>#)H#t#w3t%Zf|krii~pmF~VLGcMoRJ|;^g1q$5(Ssvb zkXC=bb$I;#UH{eF{TlY^%~rU>F6H;i^igt z5Y2&K3rM}IT~z8K>L5e;biHn<>7*BEdWwzYd4 Date: Tue, 28 Jun 2022 21:17:21 +0700 Subject: [PATCH 16/16] up chapter 7 --- .../__pycache__/tugas.cpython-310.pyc | Bin 529 -> 529 bytes Chapter06/Celery/praktikum/tugas.py | 5 ++- Chapter06/Celery/praktikum/tugas_jalan.py | 3 -- .../__pycache__/chainTopology.cpython-310.pyc | Bin 1112 -> 1145 bytes .../dockerize.py | 6 +-- .../templates/home.html | 38 ++++++++++++++++++ 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 Chapter07/codes/how to containerize a Python application/templates/home.html diff --git a/Chapter06/Celery/praktikum/__pycache__/tugas.cpython-310.pyc b/Chapter06/Celery/praktikum/__pycache__/tugas.cpython-310.pyc index b9f1375ad97e54f4545536a09d4540d48ff9610f..2c7d069a0485643d32f9e5e0584011e0e3b8c579 100644 GIT binary patch delta 77 zcmbQpGLeNZpO=@50SKm5Zc1WioXD5Lcxz&@5@XcFY4^F4GZG6*Qi}}CVv;8}Fxp8( du_dSGq!v{cF#$Ccu>pxF=EQ=6sL9tDtpQh>7DfO7 delta 77 zcmbQpGLeNZpO=@50SFXlZcO^mFp)2XF=}G56639j)9!OSXCxMsq!t;N#W+uHV6>CC e#g?3!lUh_+#01n(#0Dg8F((!j+?sri(Ha1T5g01~ diff --git a/Chapter06/Celery/praktikum/tugas.py b/Chapter06/Celery/praktikum/tugas.py index 424caca..3496855 100644 --- a/Chapter06/Celery/praktikum/tugas.py +++ b/Chapter06/Celery/praktikum/tugas.py @@ -5,7 +5,8 @@ @app.task def longtime_add(x, y): print('tugas dimulai') - # sleep 5 seconds + # sleep 5 detik time.sleep(5) print('tugas telah selesai') - return x + y \ No newline at end of file + return x + y + \ No newline at end of file diff --git a/Chapter06/Celery/praktikum/tugas_jalan.py b/Chapter06/Celery/praktikum/tugas_jalan.py index 2324d6d..26fcd6c 100644 --- a/Chapter06/Celery/praktikum/tugas_jalan.py +++ b/Chapter06/Celery/praktikum/tugas_jalan.py @@ -3,10 +3,7 @@ if __name__ == '__main__': result = tugas.longtime_add.delay(1,2) - # at this time, our task is not finished, so it will return False print ('Menunggu Proses Selesai ') - print ('Task result: ') time.sleep(10) - # now the task should be finished and ready method will return True print ('Proses telah selesai') \ No newline at end of file diff --git a/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-310.pyc b/Chapter06/Pyro4/StudiKasus/SecondExample/__pycache__/chainTopology.cpython-310.pyc index 456ddb2b5d4573f0b91758ec9f08b604c7873a02..cf9f9e83d34493e0c3b29ff4f578e18d65d0a5fe 100644 GIT binary patch delta 109 zcmcb?@soo$pO=@50SMZYHzm#7$ji;BU*~ES<5*CTlbM`Yl9``Z91~Dkl98XM8<1F( zSd^L*Uz}N7lA5a!l3G-pnv_^HS)EZ)prEoS-z28Eq% + + + + Test Docker Flask + + + +
+
+

Test

+

He di-de da-da da di de + Da-da di do-de da-re rei-ra + Obat hati ada lima perkaranya + Yang pertama, baca Qur'an dan maknanya + Yang kedua, sholat malam dirikanlah + Yang ketiga, berkumpullah dengan orang sholeh + Yang keempat, perbanyaklah berpuasa + Yang kelima, dzikir malam perpanjanglah + Salah satunya siapa bisa menjalani + Moga-moga Gusti Allah mencukupi + Obat hati ada lima perkaranya + Yang pertama, baca Qur'an dan maknanya + Yang kedua, sholat malam dirikanlah + Yang ketiga, berkumpullah dengan orang sholeh + Yang keempat, perbanyaklah berpuasa + Yang kelima, dzikir malam perpanjanglah + Salah satunya siapa bisa menjalani + Moga-moga Allah Ta'ala mencukupi + Moga-moga Allah Ta'ala mencukupi

+
+

Test html flask docker

+
+
+ + + + \ No newline at end of file