Answer the question
In order to leave comments, you need to log in
Accessing a global variable in multiprocessing?
Hello!
I wrote the code, initially sequential, without any parallelism.
def getInfo(url):
response = requests.get(url)
needToSend = true # В зависимости от логики описанной где-то выше ставим флаг
if needToSend and url not in sentLinks: # Если надо отправить и еще не отправляли
msg = ... # Формируем сообщение
bot.send_message(12345678, msg) # Шлём в телеграм
sentLinks.append(url) # И сохраняем урл чтобы на следующем круге не писать его в телеграм снова
Answer the question
In order to leave comments, you need to log in
Global variables are evil, especially in concurrent code. Just don't use them anywhere and ever. In your case, it's easy to replace the global variable with a queue .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question