following this tutorial https://github.com/Bogdanp/dramatiq I created a simple python script to check if it works or not. I did some simple operations as follows
It did work fine.
please note that there are two terminals, and one to run script and one for worker, In the script given below print statements in count_word function gets executed in second terminal
working example
import pandas as pd
import dramatiq
import requests
import sys
@dramatiq.actor
def count_words(url):
response = requests.get(url)
count = len(response.text.split(" "))
data = {'Name': ['Tom', 'nick', 'krish', 'jack'],
'Age': [20, 21, 19, 18]}
df = pd.DataFrame(data)
df.to_csv(r'C:\Users\91956\Desktop\asdf.csv')
print(df)
print(f"There are {count} words at {url!r}.")
if __name__ == "__main__":
count_words.send("http://whatsapp.com")
so I went ahead and tried to do the same thing in my flask app, i expected that the print statement in process_data will get printed in worker terminal, but it doesnt get printed at all, only "hi i am in work" gets printed in the terminal in which i run flask app
@app.route('/work')
def work():
print("hi i am in work")
@dramatiq.actor
def process_data():
print('hi i am in process_data')
process_data.send()
return "hello"
I want to run process_data function in background, I am beginner and dont know much, is it possible to achieve it the way i am doing?
so I want to know how can I run specific function in background in flask?