You never actually start the thread by calling start() on the thread object.
Do be aware that creating a background thread per request like this to do a database operation is generally a bad idea. If hit with a large number of requests you could very easily overwhelm the number of allowed database connections. You also aren't cleaning up the state of the thread by calling join() on it afterwards either. Is there a reason you aren't doing this within the context of the request rather than in a background thread? Graham > On 27 Sep 2020, at 9:23 pm, Charlie <[email protected]> wrote: > > My code is : > > from threading import Thread > > class SQLThread(Thread): > > def __init__(self, id): > print(' SQLThread ') > Thread.__init__(self) > self.id = id > self._fullname = None > > def run(self): > try: > print('run') > connection = MySQLdb.connect(MYSQL_SERVER, > MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB, connect_timeout=2) > cursor = connection.cursor() > self._fullname = get_user_fullname(cursor, self.id) > connection.close() > except MySQLdb.Error as e: > print('SQLThread: %s' % e) > > Sorry, i thought the threads never run because 'run' is not written in the > apache log file whereas ' SQLThread' is written. Do you know why ? > Le dimanche 27 septembre 2020 à 12:04:03 UTC+2, Graham Dumpleton a écrit : > Would need to see an example of the code you are talking about to understand > better what you are talking about. In particular, how are you creating the > threads and where? How are you waiting on the threads to complete, etc? > > Also, are you using manually configure Apache/mod_wsgi or are you using > mod_wsgi-express? If manually configure Apache/mod_wsgi, how are you > configuring mod_wsgi? > > Graham > > >> On 27 Sep 2020, at 8:01 pm, Charlie <[email protected] >> <applewebdata://D1AD3CAA-9EC7-40AA-980F-919EB78DACDC>> wrote: >> > >> I use threading module for concurrent SQL queries. Using a simple python >> script, all threads run normaly but when i use the same code in a WSGI app, >> the threads never start >> >> Thanks for your help >> >> Charlie >> > >> -- >> You received this message because you are subscribed to the Google Groups >> "modwsgi" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] >> <applewebdata://D1AD3CAA-9EC7-40AA-980F-919EB78DACDC>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/modwsgi/b2e6594a-0477-4b4e-a2b6-bba162922296n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/modwsgi/b2e6594a-0477-4b4e-a2b6-bba162922296n%40googlegroups.com?utm_medium=email&utm_source=footer>. > > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/modwsgi/899fb259-674c-4b02-bded-906274f18321n%40googlegroups.com > > <https://groups.google.com/d/msgid/modwsgi/899fb259-674c-4b02-bded-906274f18321n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/800A9FD1-2FBA-4BC9-B018-249846CC420D%40gmail.com.
