473,395 Members | 1,689 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,395 software developers and data experts.

threads and return values

say i'm issuing

t = Thread(target=lambda: WeeklyReportPDF.MakeReport(self.UserNameValue,
self.PassWordValue,ReportType,self.db))
t.start()

which works just fine, BUT how do i get access to the return value of
WeeklyReportPDF.MakeReport() ??

Sep 14 '06 #1
2 1273
Timothy Smith <ti*****@open-networks.netwrites:
t = Thread(target=lambda:
WeeklyReportPDF.MakeReport(self.UserNameValue,
self.PassWordValue,ReportType,self.db))
t.start()

which works just fine, BUT how do i get access to the return value of
WeeklyReportPDF.MakeReport() ??
You can't. Make the function send you a message through some
synchronized communication mechanism. The Pythonic favorite way to do
that is with Queue, even when it's just one value (untested):

import Queue
q = Queue()
t = Thread(target = lambda q=q: q.put(WeeklyReportPDF.MakeReport(...)))
t.start()
...

Now if you say

value = q.get()

the caller will block until WeeklyReportPDF.MakeReport returns. If
you say

value = q.get(False)

the False argument says not to block, so if WeeklyReportPDF.MakeReport
hasn't yet returned, q.get will raise the Queue.Empty exception, which
you can then catch and deal with. Another arg lets you specify a
timeout:

value = q.get(False, 3.0)

blocks for up to 3 seconds, then raises Queue.Empty.
Sep 14 '06 #2
Paul Rubin <http://ph****@NOSPAM.invalidwrites:
import Queue
q = Queue()
Oops, meant

q = Queue.Queue()
Sep 14 '06 #3

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

Similar topics

5
by: Rob | last post by:
Hi there, Firstly, apologies for x-post but I'm hoping the post is relevant to both groups... I have written a native implementation in C, and a java wrapper class. This all works fine and...
17
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next...
9
by: David Poundall | last post by:
I have a thread class and I want to be able to track its usage within an application. FYI the class launches aplications in their own thread when the 'launch' method is called. That works OK ...
6
by: sathyashrayan | last post by:
Following are the selected thread from the date:30-jan-2005 to 31-jan-2005. I did not use any name because of the subject is important. You can get the original thread by typing the subject...
5
by: Leonardo Hyppolito | last post by:
Hello! I am trying to implement a program that uses Threads. I chose the producers and consumers scenario. The producers put a "product" (which is an int number) in a shared storage place of one...
6
by: Quiet Man | last post by:
Hi all, I'm designing a fairly simple service that will run on W2K/SP4 and W2K3 servers. It's job is to be a very specialized database server that listens on a given IP address / TCP port and...
4
by: Fred West | last post by:
I have a class with a private Int32 data member that gets modified from multiple background threads. To synchronize these modifications I use the lock statement: Int32 count = 0; object...
4
by: MSDousti | last post by:
Hi I have written a VB .NET app, which uses several threads. I thought that when the user closes the main window (when MainForm.closed event occures, and I call application.exit) all running...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
1
by: Chris Roth | last post by:
I've been working with boost::threads to do some multithreading in my code and have run into some questions that I haven't been able to find answers to. I'll include some sample code to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.