Thursday 15 May 2014

python - Is there any way to make data corruption intentionally in python3? -



python - Is there any way to make data corruption intentionally in python3? -

i'm making application corrupts data. that's does. however, cannot find ways save corrupted info variable. want corrupted info saved in python list "holder=[]" create them accessible later. there way that?

import random import time import threading def example(): counter in range(10): print(counter) def thread_set_1(): thread1=threading.thread(target=example) thread2=threading.thread(target=example) thread3=threading.thread(target=example) thread4=threading.thread(target=example) thread5=threading.thread(target=example) thread6=threading.thread(target=example) thread7=threading.thread(target=example) thread8=threading.thread(target=example) thread1.start() thread2.start() thread3.start() thread4.start() thread5.start() thread6.start() thread7.start() thread8.start() def thread_set_2(): thread1=threading.thread(target=thread_set_1) thread2=threading.thread(target=thread_set_1) thread3=threading.thread(target=thread_set_1) thread4=threading.thread(target=thread_set_1) thread5=threading.thread(target=thread_set_1) thread6=threading.thread(target=thread_set_1) thread7=threading.thread(target=thread_set_1) thread8=threading.thread(target=thread_set_1) thread1.start() thread2.start() thread3.start() thread4.start() thread5.start() thread6.start() thread7.start() thread8.start()

if understand correctly, save output? think won't possible using simple array, global interpreter lock going prevent simultaneous access multiple threads global variable. however, if write output file, work. if alter function example so:

def example(): counter in range(10): open('testfile.txt','a') fid: fid.write(str(counter))

and run:

open('testfile.txt','w') #create empty file thread_set_1() thread_set_2()

testfile.txt contain seemingly random numbers. however, going slow, file going opened , closed every time number written.

the main reason not utilize procedure create random numbers not going random, numbers written file going increment time. wrote plan on shuffling numbers afterwards; if plan on using random (it among imports), why want additionally create own random number generator?

python python-2.7 python-3.x

No comments:

Post a Comment