turning my multithreading code into multiprocessing /u/qhelspil Python Education

turning my multithreading code into multiprocessing /u/qhelspil Python Education

i want to record 2 audios at the same time.

using multithreadind this code works fine

import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

using multiprocessing, i just replaced the classes and the result is

import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”)

however it is not recording anything, it prints ‘recordings completed’ instantly

what am i doing wrong?

thanks

submitted by /u/qhelspil
[link] [comments]

​r/learnpython i want to record 2 audios at the same time. using multithreadind this code works fine import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) using multiprocessing, i just replaced the classes and the result is import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”) however it is not recording anything, it prints ‘recordings completed’ instantly what am i doing wrong? thanks submitted by /u/qhelspil [link] [comments] 

i want to record 2 audios at the same time.

using multithreadind this code works fine

import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

using multiprocessing, i just replaced the classes and the result is

import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”)

however it is not recording anything, it prints ‘recordings completed’ instantly

what am i doing wrong?

thanks

submitted by /u/qhelspil
[link] [comments]  i want to record 2 audios at the same time. using multithreadind this code works fine import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) using multiprocessing, i just replaced the classes and the result is import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”) however it is not recording anything, it prints ‘recordings completed’ instantly what am i doing wrong? thanks submitted by /u/qhelspil [link] [comments]

Read more

How do I code a 40gb OneDrive File without downloading? /u/Butterlover1996 Python Education

How do I code a 40gb OneDrive File without downloading? /u/Butterlover1996 Python Education

I have a 40gb OneDrive File with 50ish csv files of data for the last 4 years (one month per csv). So I downloaded a few files, like the latest months, did my analysis and now I just have to clean up the rest and apply my analysis to a large scale. Problem is that I do not want to download the entire library. I mean there has to be a way to do python and pandas on this file without downloading the whole thing. This is the first time I am doing something like this. My old job was multiple analysis of multiple products but at least the files where small (Less than 3 gb). Now my new job is only three things to analyze but the files are huge.

submitted by /u/Butterlover1996
[link] [comments]

​r/learnpython I have a 40gb OneDrive File with 50ish csv files of data for the last 4 years (one month per csv). So I downloaded a few files, like the latest months, did my analysis and now I just have to clean up the rest and apply my analysis to a large scale. Problem is that I do not want to download the entire library. I mean there has to be a way to do python and pandas on this file without downloading the whole thing. This is the first time I am doing something like this. My old job was multiple analysis of multiple products but at least the files where small (Less than 3 gb). Now my new job is only three things to analyze but the files are huge. submitted by /u/Butterlover1996 [link] [comments] 

I have a 40gb OneDrive File with 50ish csv files of data for the last 4 years (one month per csv). So I downloaded a few files, like the latest months, did my analysis and now I just have to clean up the rest and apply my analysis to a large scale. Problem is that I do not want to download the entire library. I mean there has to be a way to do python and pandas on this file without downloading the whole thing. This is the first time I am doing something like this. My old job was multiple analysis of multiple products but at least the files where small (Less than 3 gb). Now my new job is only three things to analyze but the files are huge.

submitted by /u/Butterlover1996
[link] [comments]  I have a 40gb OneDrive File with 50ish csv files of data for the last 4 years (one month per csv). So I downloaded a few files, like the latest months, did my analysis and now I just have to clean up the rest and apply my analysis to a large scale. Problem is that I do not want to download the entire library. I mean there has to be a way to do python and pandas on this file without downloading the whole thing. This is the first time I am doing something like this. My old job was multiple analysis of multiple products but at least the files where small (Less than 3 gb). Now my new job is only three things to analyze but the files are huge. submitted by /u/Butterlover1996 [link] [comments]

Read more

How do you guys deal when you reach a mental obstacle? /u/Bulky_Slice_235 Python Education

How do you guys deal when you reach a mental obstacle? /u/Bulky_Slice_235 Python Education

Hey all!

So I have been learning to program using the book Automate the boring stuff, and it has been an amazing journey so far. I have learned things that I didn’t knew about programing (Even tho I still feel like I have to go more deep with concepts and stuff like that) and have been able to do the projects the book gives as a challenge. On the side, I was able to automate a process that used to take me a whole day, and now it takes me 30 minutes. Right now tho, I’m getting onto the frustrating projects (at least for me as a begginer) from the book and it seems I can’t find a solution to continue. I was wondering what is your go to method (as pro programmers) to moments when you feel you can’t find a solution to your problem.

submitted by /u/Bulky_Slice_235
[link] [comments]

​r/learnpython Hey all! So I have been learning to program using the book Automate the boring stuff, and it has been an amazing journey so far. I have learned things that I didn’t knew about programing (Even tho I still feel like I have to go more deep with concepts and stuff like that) and have been able to do the projects the book gives as a challenge. On the side, I was able to automate a process that used to take me a whole day, and now it takes me 30 minutes. Right now tho, I’m getting onto the frustrating projects (at least for me as a begginer) from the book and it seems I can’t find a solution to continue. I was wondering what is your go to method (as pro programmers) to moments when you feel you can’t find a solution to your problem. submitted by /u/Bulky_Slice_235 [link] [comments] 

Hey all!

So I have been learning to program using the book Automate the boring stuff, and it has been an amazing journey so far. I have learned things that I didn’t knew about programing (Even tho I still feel like I have to go more deep with concepts and stuff like that) and have been able to do the projects the book gives as a challenge. On the side, I was able to automate a process that used to take me a whole day, and now it takes me 30 minutes. Right now tho, I’m getting onto the frustrating projects (at least for me as a begginer) from the book and it seems I can’t find a solution to continue. I was wondering what is your go to method (as pro programmers) to moments when you feel you can’t find a solution to your problem.

submitted by /u/Bulky_Slice_235
[link] [comments]  Hey all! So I have been learning to program using the book Automate the boring stuff, and it has been an amazing journey so far. I have learned things that I didn’t knew about programing (Even tho I still feel like I have to go more deep with concepts and stuff like that) and have been able to do the projects the book gives as a challenge. On the side, I was able to automate a process that used to take me a whole day, and now it takes me 30 minutes. Right now tho, I’m getting onto the frustrating projects (at least for me as a begginer) from the book and it seems I can’t find a solution to continue. I was wondering what is your go to method (as pro programmers) to moments when you feel you can’t find a solution to your problem. submitted by /u/Bulky_Slice_235 [link] [comments]

Read more

How can I improve the code in this Python project? /u/GrizzyLizz Python Education

How can I improve the code in this Python project? /u/GrizzyLizz Python Education

Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool

So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API

I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions.

submitted by /u/GrizzyLizz
[link] [comments]

​r/learnpython Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions. submitted by /u/GrizzyLizz [link] [comments] 

Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool

So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API

I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions.

submitted by /u/GrizzyLizz
[link] [comments]  Link: https://gitlab.com/__muditj__/gmail-cli-automation-tool So I was given an assignment task for hiring and I ended up rushing through it a little so I didnt do so well. The task was: Given a rules.json file which defines certain filters for emails based on different fields like From, Subject, Content etc, filter out the emails which obey the rules and apply the specified actions on them. This is a CLI application where I make use of OAuth2 to authenticate with Google’s Gmail API I am aware that there are excessive print statements and I dont have any unit tests added but apart from this, in what other ways can I improve the codebase? In particular, I want to know what would be the ideal way to package this application. This was meant to be a CLI application which should be runnable as a script so I have two particular Python files with a “if __name__ == “__main__” block inside them. One is to authenticate with Google OAuth and get the access and refresh token and the other is to run the main part of the application which does the filtering of the emails and applies the specified actions. submitted by /u/GrizzyLizz [link] [comments]

Read more

Python library documentation /u/Classic_essays Python Education

Python library documentation /u/Classic_essays Python Education

Hello guys.

I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting.

However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated.

Thanks

submitted by /u/Classic_essays
[link] [comments]

​r/learnpython Hello guys. I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting. However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated. Thanks submitted by /u/Classic_essays [link] [comments] 

Hello guys.

I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting.

However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated.

Thanks

submitted by /u/Classic_essays
[link] [comments]  Hello guys. I’m working on an opensource library and I need to start documenting it. I will use Readthedocs for hosting. However, I’m caught between using mkdocs and sphnix. Any advice on this would be greatly appreciated. Thanks submitted by /u/Classic_essays [link] [comments]

Read more

How bad is this method of getting Even/Odd? /u/VanClyded Python Education

How bad is this method of getting Even/Odd? /u/VanClyded Python Education

Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work?
Example using said line of code;

num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”)

So my question is, am i just lucky or is this a *appropriate* way to get this?

submitted by /u/VanClyded
[link] [comments]

​r/learnpython Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work? Example using said line of code; num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”) So my question is, am i just lucky or is this a *appropriate* way to get this? submitted by /u/VanClyded [link] [comments] 

Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work?
Example using said line of code;

num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”)

So my question is, am i just lucky or is this a *appropriate* way to get this?

submitted by /u/VanClyded
[link] [comments]  Been getting back into Python and i needed to find even/odd numbers in a short list, came up with a ridiculous line of code that seem… to work? Example using said line of code; num = input(“Number: “) if float(num)/2 – int(int(num)/2) == 0: print(“EVEN”) else: print(“ODD”) So my question is, am i just lucky or is this a *appropriate* way to get this? submitted by /u/VanClyded [link] [comments]

Read more

Help with making a computer for school project /u/deathnote9 Python Education

Help with making a computer for school project /u/deathnote9 Python Education

My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated.

https://pastebin.com/dsCeAbTP

https://pastebin.com/2PqcJus0

submitted by /u/deathnote9
[link] [comments]

​r/learnpython My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated. https://pastebin.com/dsCeAbTP https://pastebin.com/2PqcJus0 submitted by /u/deathnote9 [link] [comments] 

My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated.

https://pastebin.com/dsCeAbTP

https://pastebin.com/2PqcJus0

submitted by /u/deathnote9
[link] [comments]  My connect 4 program is in two files below. So I have to make a computer that drops random spots unless it has a winning play. I got the random part down but not sure how to get the second part. Any help would be appreciated. https://pastebin.com/dsCeAbTP https://pastebin.com/2PqcJus0 submitted by /u/deathnote9 [link] [comments]

Read more

Where to learn project organization? /u/Waveover Python Education

Where to learn project organization? /u/Waveover Python Education

I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time.

Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer.

What or where should I learn to make that next step?

submitted by /u/Waveover
[link] [comments]

​r/learnpython I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time. Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer. What or where should I learn to make that next step? submitted by /u/Waveover [link] [comments] 

I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time.

Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer.

What or where should I learn to make that next step?

submitted by /u/Waveover
[link] [comments]  I’m getting to the point where I am building bigger projects in python now, but after a while the project becomes too big that I find it too much work to make any new changes and leave the project as is for long periods of time. Where can I learn how to structure my projects better so that even as my project grows I can keep working on it? To add some context I would consider myself a bit above beginner. I am able to create different files and seperate out my code into functions and try keep modules cohesively tight. I don’t really use classes though. I wonder if that is the big issue for me. Or its more of high level concepts as far as organizing and structuring my code that I need to learn as a developer. What or where should I learn to make that next step? submitted by /u/Waveover [link] [comments]

Read more