473,385 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Towards thread groups?

Hello,

I am the author of OfflineIMAP[1], a program that currently is a heavy
user of threads. For various reasons (see below), thread groups are
something that is highly desirable for me in Python. Is anyone aware
of an implementation of thread groups for Python? Is anyone else
working on this? Is anyone else experiencing this sort of pain?

Here's why I need this:

OfflimeIMAP is a bi-directional IMAP/Maildir synchronization system.
It can synchronize multiple accounts at once. Within a given account,
it can synchronize multiple folders at once. Within a given folder,
it can synchronize multiple messages at once. All these simultaneous
actions are handled by threads. (In case you're wondering, there are
bounds in the system to prevent this all from running away.)

Right now, error handling is not very good. Let's say that one of the
5 connections to an IMAP server for Account A dies on us and we get a
network exception. Ideally, with this condition, I would shut down
all the other threads processing Account A, terminate its open
connections, and restart it. (An unexpected error can leave
OfflineIMAP with an incorrect idea of what is on the server, so the
safest thing to do is reset the algorithm and thus get updates from
the server on what exactly it knows about.)

However, I can't do that with the current system. The best thing I
can do is catch the exception and transmit it to an exception handling
thread. (By overriding methods of the Thread object.) That's close,
but...

The exception handling thread can do things like print out the error.
But the recourses available to it are: 1) terminate the entire
application, and 2) ignore the error. Option #2 is not satisfactory,
to the only remaining option is #1.

Here are some other things that won't work:

* Putting all network code within a try block.

Several problems with that: the exceptions thrown are different for
different types of connections (plain socket, ssl, etc), and may
not be known in advance.

Moreover, actions such as "download message" are done in individual
threads, and the parent thread -- which really needs to know about
this -- has no way to get the message until it does a join, which
it may or may not ever have cause to do. Even then, it would
usually be better for it to get the message immediately.

* Save some state on thread exit and retrieve it on join().

Possible, yes, and might be a usable workaround. However, there
are a number of places in the code that don't do a join(), and this
seems an error-prone way of doing things.

It basically involves manually passing data back up the "thread
chain", like passing error codes back up through the call chain in
C. Essentially, many of the benefits of exceptions in the first
place disappear.

Thoughts anyone?

[1] OfflineIMAP is at http://quux.org/devel/offlineimap

-- John Goerzen
Jul 18 '05 #1
0 1339

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
1
by: Oleg Paraschenko | last post by:
Hello, those who are still interested in "lisp vs xml" and "xml is a poor copy of s-expressions" issues, might find my recent writings interesting: Towards s-expression based XPath/XSLT...
6
by: Extremest | last post by:
I am new to threading and trying to figure some things out. Are all variables in a thread set to only that thread? Meaning if I create 2 instances of a class and then put each one in a different...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.