save multi thread output to txt file












-3















i write this simple code ... i need to save the code output to text file in my pc how i can do that ?



import threading
import time


def qan(hey):
while True:

d = hey + 1
print d
time.sleep(1)


def printd(printme):
while True:
print printme + "n"
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()


and this is my code output




hey



2 2 hey



2hey



2











share|improve this question























  • Possible duplicate of many threads to write log file at same time python

    – user10455554
    Nov 26 '18 at 9:12
















-3















i write this simple code ... i need to save the code output to text file in my pc how i can do that ?



import threading
import time


def qan(hey):
while True:

d = hey + 1
print d
time.sleep(1)


def printd(printme):
while True:
print printme + "n"
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()


and this is my code output




hey



2 2 hey



2hey



2











share|improve this question























  • Possible duplicate of many threads to write log file at same time python

    – user10455554
    Nov 26 '18 at 9:12














-3












-3








-3








i write this simple code ... i need to save the code output to text file in my pc how i can do that ?



import threading
import time


def qan(hey):
while True:

d = hey + 1
print d
time.sleep(1)


def printd(printme):
while True:
print printme + "n"
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()


and this is my code output




hey



2 2 hey



2hey



2











share|improve this question














i write this simple code ... i need to save the code output to text file in my pc how i can do that ?



import threading
import time


def qan(hey):
while True:

d = hey + 1
print d
time.sleep(1)


def printd(printme):
while True:
print printme + "n"
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()


and this is my code output




hey



2 2 hey



2hey



2








python windows multithreading save python-multithreading






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 9:09









evilcode1evilcode1

328




328













  • Possible duplicate of many threads to write log file at same time python

    – user10455554
    Nov 26 '18 at 9:12



















  • Possible duplicate of many threads to write log file at same time python

    – user10455554
    Nov 26 '18 at 9:12

















Possible duplicate of many threads to write log file at same time python

– user10455554
Nov 26 '18 at 9:12





Possible duplicate of many threads to write log file at same time python

– user10455554
Nov 26 '18 at 9:12












1 Answer
1






active

oldest

votes


















0














Use some buffer with data:



import threading
import time


buffer =

def qan(hey):
while True:

d = hey + 1
buffer.append(d)
time.sleep(1)


def printd(printme):
while True:
buffer.append(printme + "n")
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()

with open('output.txt') as f:
f.write(''.join(buffer))





share|improve this answer
























  • its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

    – evilcode1
    Nov 26 '18 at 10:38













  • output : ['heyn', 2] just oneline !!

    – evilcode1
    Nov 26 '18 at 10:38











  • rewrite first buffer.append as buffer.append(str(d) + 'n')

    – Nick
    Nov 26 '18 at 10:40













  • First of all, print in python prints string with 'n' , and join method works only with list strings

    – Nick
    Nov 26 '18 at 10:42













  • so how i can solve this issue ?

    – evilcode1
    Dec 4 '18 at 16:29












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477776%2fsave-multi-thread-output-to-txt-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Use some buffer with data:



import threading
import time


buffer =

def qan(hey):
while True:

d = hey + 1
buffer.append(d)
time.sleep(1)


def printd(printme):
while True:
buffer.append(printme + "n")
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()

with open('output.txt') as f:
f.write(''.join(buffer))





share|improve this answer
























  • its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

    – evilcode1
    Nov 26 '18 at 10:38













  • output : ['heyn', 2] just oneline !!

    – evilcode1
    Nov 26 '18 at 10:38











  • rewrite first buffer.append as buffer.append(str(d) + 'n')

    – Nick
    Nov 26 '18 at 10:40













  • First of all, print in python prints string with 'n' , and join method works only with list strings

    – Nick
    Nov 26 '18 at 10:42













  • so how i can solve this issue ?

    – evilcode1
    Dec 4 '18 at 16:29
















0














Use some buffer with data:



import threading
import time


buffer =

def qan(hey):
while True:

d = hey + 1
buffer.append(d)
time.sleep(1)


def printd(printme):
while True:
buffer.append(printme + "n")
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()

with open('output.txt') as f:
f.write(''.join(buffer))





share|improve this answer
























  • its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

    – evilcode1
    Nov 26 '18 at 10:38













  • output : ['heyn', 2] just oneline !!

    – evilcode1
    Nov 26 '18 at 10:38











  • rewrite first buffer.append as buffer.append(str(d) + 'n')

    – Nick
    Nov 26 '18 at 10:40













  • First of all, print in python prints string with 'n' , and join method works only with list strings

    – Nick
    Nov 26 '18 at 10:42













  • so how i can solve this issue ?

    – evilcode1
    Dec 4 '18 at 16:29














0












0








0







Use some buffer with data:



import threading
import time


buffer =

def qan(hey):
while True:

d = hey + 1
buffer.append(d)
time.sleep(1)


def printd(printme):
while True:
buffer.append(printme + "n")
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()

with open('output.txt') as f:
f.write(''.join(buffer))





share|improve this answer













Use some buffer with data:



import threading
import time


buffer =

def qan(hey):
while True:

d = hey + 1
buffer.append(d)
time.sleep(1)


def printd(printme):
while True:
buffer.append(printme + "n")
time.sleep(1)


t1 = threading.Thread(target=qan, args=(1,))
t2 = threading.Thread(target=printd, args=("hey",))
t2.start()
t1.start()

with open('output.txt') as f:
f.write(''.join(buffer))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 9:14









NickNick

2998




2998













  • its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

    – evilcode1
    Nov 26 '18 at 10:38













  • output : ['heyn', 2] just oneline !!

    – evilcode1
    Nov 26 '18 at 10:38











  • rewrite first buffer.append as buffer.append(str(d) + 'n')

    – Nick
    Nov 26 '18 at 10:40













  • First of all, print in python prints string with 'n' , and join method works only with list strings

    – Nick
    Nov 26 '18 at 10:42













  • so how i can solve this issue ?

    – evilcode1
    Dec 4 '18 at 16:29



















  • its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

    – evilcode1
    Nov 26 '18 at 10:38













  • output : ['heyn', 2] just oneline !!

    – evilcode1
    Nov 26 '18 at 10:38











  • rewrite first buffer.append as buffer.append(str(d) + 'n')

    – Nick
    Nov 26 '18 at 10:40













  • First of all, print in python prints string with 'n' , and join method works only with list strings

    – Nick
    Nov 26 '18 at 10:42













  • so how i can solve this issue ?

    – evilcode1
    Dec 4 '18 at 16:29

















its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

– evilcode1
Nov 26 '18 at 10:38







its now working u got an error after i modify the code : with open('output.txt' , "a") as f: f.write('n'.join(str(buffer)) )

– evilcode1
Nov 26 '18 at 10:38















output : ['heyn', 2] just oneline !!

– evilcode1
Nov 26 '18 at 10:38





output : ['heyn', 2] just oneline !!

– evilcode1
Nov 26 '18 at 10:38













rewrite first buffer.append as buffer.append(str(d) + 'n')

– Nick
Nov 26 '18 at 10:40







rewrite first buffer.append as buffer.append(str(d) + 'n')

– Nick
Nov 26 '18 at 10:40















First of all, print in python prints string with 'n' , and join method works only with list strings

– Nick
Nov 26 '18 at 10:42







First of all, print in python prints string with 'n' , and join method works only with list strings

– Nick
Nov 26 '18 at 10:42















so how i can solve this issue ?

– evilcode1
Dec 4 '18 at 16:29





so how i can solve this issue ?

– evilcode1
Dec 4 '18 at 16:29




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53477776%2fsave-multi-thread-output-to-txt-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen