D
D
Dmitry Filatov2014-08-19 22:00:44
Django
Dmitry Filatov, 2014-08-19 22:00:44

Trheadind (threads) works on Win but doesn't work on Linux. Why?

On a laptop with VIN, the code works fine, it does everything. But on Linux, threads don't start. Ubuntu on digitalocean. What could be the problem?

import threading

        def wright_to_google_doc_table(data):
            '''
            Функция записывает переданные в словаре данные
            в таблицу на GoogleDocs.
            Создает необходимый лист для города, если нужно.
            Состав словаря:
                data['city_slu'] - используется для имени листа таблицы
                data['name']
                data['phone']
                data['email']
            '''
            # данные для авторизации таблицы - логин, пароль, код из ссылки таблицы.
            gc = gspread.login('[email protected]', 'xxxxxxxxxxxxxxxxx')
            document = gc.open_by_key('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
            try:
                table = document.worksheet(data['city_slug'])
            except:
                table = document.add_worksheet(data['city_slug'], 1, 3)
                table.update_acell('A1', u'ФИО')
                table.update_acell('B1', u'Телефон')
                table.update_acell('C1', u'Почта')
            finally:
                table.append_row([data['name'], data['phone'], data['email']])

        messages.success(self.request, self.success_message, u'openning_soon_success')
        city = self.get_city()
        data = {'city_slug': city.slug,
                'name': self.request.POST['name'],
                'phone': self.request.POST['phone'],
                'email': self.request.POST['email']}

        # выполняем функцию асинхронно
        t = threading.Thread(target=wright_to_google_doc_table,
                             args=(data,))
        t.setDaemon(True)
        t.start()

        return render(self.request, self.template_name, {})

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Filatov, 2014-08-28
@i_dozi

If someone comes across this, it helped me to use multiprocessing instead of threading

D
Disassociative, 2014-08-20
@Disassociative

Perhaps an error occurs in your wonderful Try Except block, try to catch what you expect, and not all errors.

A
Andrey Grinevich, 2014-08-19
@Derfirm

t.daemon = True
t.start() Have
you tried it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question