[sqlalchemy] Re: Can anyone explain me why my thread block ???
Hi, I found what block my print in my thread. It s not sql alchemy library, it s MySQLdb... They import directly in the function, import block print in threads I modified the library (imports move out of the method) and it works very well now. I can now run asynchronous queries so my gui don t freeze. from constants import CLIENT, FIELD_TYPE from converters import conversions from weakref import proxy, WeakValueDictionary import types kwargs2 = kwargs.copy() if kwargs.has_key('conv'): conv = kwargs['conv'] else: -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] No import in function and method = thread firendly
Hi again, I understand all! SqlAlchemy and MySQLdb don t respect this rule 16.2.9 http://docs.python.org/library/threading.html#threaded-imports Why? :( -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] No import in function and method = thread firendly
Hello Michael, Thx for answer. Of course, there is no thread in mysqldb but there is import in function connect line 73 of __init__.py and line 128 to 132 of connections.py in method __init__(self, *args, **kwargs): So when i use connect function in my thread, it blocks because it encounters the import of the library. I rework mysqldb files, i move import out of functions and my thread program which use mysqldb works : no deadlock. I tried to do the same with sqlalchemy library but it s too hard, i failed. So i can only use mysqldb in my thread though i want to use sqlalchemy which is better to manipulate db. correction, it doesn't even say that. All it says regarding deadlocks is that an import shouldn't spawn a thread. SQLAlchemy does not spawn any threads (pretty sure MySQLdb doesn't, either). On May 2, 2010, at 11:28 AM, Michael Bayer wrote: Where do you see SQLAlchemy spawning any threads ?Its the responsibility of the threaded application to make sure all imports occur before threads are spawned. The documentation you refer to states as much. On May 2, 2010, at 8:34 AM, christiandemo...@gmail.com wrote: Hi again, I understand all! SqlAlchemy and MySQLdb don t respect this rule 16.2.9 http://docs.python.org/library/threading.html#threaded-imports Why? :( -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] No import in function and method = thread firendly
Hi All it says regarding deadlocks is that an import shouldn't spawn a thread Can you explain me why import math (whick don t spawn a thread) block this thread (only one ok appear in terminal)? When i remove import math, ok appears continuously in term. I don t understand class SyncTopAppel(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.running = False def run(self): self.running = True while self.running: print ok import math time.sleep(1) def stop(self): self.running = False All it says regarding deadlocks is that an import shouldn't spawn a threa -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
Re: [sqlalchemy] No import in function and method = thread firendly
Ok i found this subject which explain why. http://www.mail-archive.com/python-...@python.org/msg24747.html The deadlock happens because strptime has an import inside it, and recursive imports are not allowed in different threads. This situation is well known, found a lot of references to this import-thread-import problem in discussions and previous bugs (i.e.: http://bugs.python.org/issue683658). I'm not sure how anyone could tell more. There are some locks and you're staring at a deadlock. This isn't rare in threaded programs, alas. Are you by any chance spawning and executing a thread as a side-effect of doing an import, where the spawned thread itself does an import and the spawning code waits for the spawned thread to finish? If so, the spawning thread would wait forever on whatever gimmick it's using to wait for the spawned thread to finish, and the spawned thread would wait forever for the global import lock to get released (which can't happen, because the global import lock is waiting for the spawning thread to release it, but the spawning thread is waiting for the spawned thread to finish). Or, more simply, never spawn a thread as a side-effect of importing. Sry for inconvenience Chris correction, it doesn't even say that. All it says regarding deadlocks is that an import shouldn't spawn a thread. SQLAlchemy does not spawn any threads (pretty sure MySQLdb doesn't, either). On May 2, 2010, at 11:28 AM, Michael Bayer wrote: Where do you see SQLAlchemy spawning any threads ?Its the responsibility of the threaded application to make sure all imports occur before threads are spawned. The documentation you refer to states as much. On May 2, 2010, at 8:34 AM, christiandemo...@gmail.com wrote: Hi again, I understand all! SqlAlchemy and MySQLdb don t respect this rule 16.2.9 http://docs.python.org/library/threading.html#threaded-imports Why? :( -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
[sqlalchemy] Can anyone explain me why my thread block ???
Hello everybody, i want to use SqlAlchemy in a thread but i have a problem. Here two files : *Orm.py* # -*- coding: ISO-8859-15 -*- from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.sql import func, exists from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.orm.query import Query # from sqlalchemy.types import * engine = create_engine(mysql://root:@localhost/alertesms) Base = declarative_base() class compte(Base): __tablename__ = 'compte' codeCompte = Column('codeCompte', Integer, primary_key=True) serveurMail = Column('serveurMail', String) portMail = Column('portMail', Integer) ssl = Column('ssl', Integer) loginMail = Column('loginMail', String) motDePasseMail = Column('motDePasseMail', String) tel1 = Column('tel1', String) credit = Column('credit', Integer) def __init__(self, serveurMail=, portMail=0, ssl=0, loginMail=, motDePasseMail=, tel1=, credit=10): self.serveurMail=serveurMail self.portMail=portMail self.ssl=ssl self.loginMail=loginMail self.motDePasseMail=motDePasseMail self.tel1=tel1 self.credit=credit class Query(Query): def __init__(self, *arg, **kw): self._populate_existing = True super(Query, self).__init__(*arg, **kw) def get_scoped_session(): return scoped_session(sessionmaker(autocommit=False, autoflush=False, expire_on_commit=False, bind=engine, query_cls=Query)) def get_session(): scoped_session = get_scoped_session() return scoped_session() session = get_scoped_session() *Surveillance.py* # -*- coding: ISO-8859-15 -*- import time import threading import ExtractionMail import Orm class SyncTopAppel(threading.Thread): Déclencheur des tops d'exécution def __init__(self): threading.Thread.__init__(self) self.running = False def run(self): self.running = True while self.running: print debut self.session = Orm.get_session() print self.session *# print self.session.query(Orm.compte)* print fin time.sleep(1) def stop(self): self.running = False All is fine but when i remove comment line in my thread, the thread block and the prints doesn t continue ^^ why? Chris -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en. attachment: moz-screenshot-2.pngattachment: moz-screenshot-3.png