Control over individual threads

Hello dear community,

I have another stupid question:

I would like to run an asynchronous process in Plone.

I have discovered the utils dm.zodb.asynchronous with which I can do it with
s = TransactionalScheduler()
sid = s.schedule(..)

to start a process in another thread but how do I get access to the thread (i.e. the object) from outside ? I want to pass variables to it to end it (this process is in a while loop)

Or is there a better way to create a second thread in Plone/Zope?

I would be very happy about help.

Greetings :slight_smile:

There are no stupid questions as the missive goes (that award is normally reserved for the question(s) not asked).

  • Can you further elaborate on what your use-case is?
  • What is it that you're trying to accomplish?

The mentioned utility is for asynchronous access to your ZODB. Are you sure that is what you wish to implement? Or are you looking for asynchronous task management using either celery & Redis/Memcache for example?

Dieter is the author of the utility you're currently looking at, perhaps he'll be able to chime in once you give just a brief overview of what you're trying to accomplish.

Cheers!

1 Like

dm.zodb.asynchronous hides the thread. As you have seen in its documentation, you can however pass arguments to the scheduled function. You can pass e.g. a "condition variable" (or other Python objects for synchronization) to communicate with the thread.

dm.zodb.asynchronous tries to facilitate asynchronous tasks which either must integrate with the transaction mechanism of the ZODB or access persistent objects stored in the ZODB. If your asynchronous tasks do not have those requirements, you can use Python's standard mechanisms to create (and control) threads. If your application requires both explicit access to the thread object as well as integration with the ZODB, you can look at the implementation of dm.zodb.asynchronous and extract/modify as necessary.

1 Like

Hello, I have a python library (psycopg) that "waits" for triggers in a database. and I want to start a seprate thread for this.But I also want to have control over it

Hello But how can I pass the "condition variable" while the thread is already running ?

Moment, can you just use pure python to open a second thread in Plone ? I was told that was not possible

You create the condition variable (or other communication facility) before you pass it to the function; the thread can then use them without that the external world knows the thread (object) itself.

You can. Only when this thread needs to access persistent objects, this must happen in a way compatible with the ZODB.

1 Like