473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling functions at the same time

I need a script to call several functions at the same time. How does one
call more than one function simultaneously?

Jul 18 '05 #1
18 5277
bart_nessux wrote:

I need a script to call several functions at the same time. How does one
call more than one function simultaneously?


You can call them pseudo-concurrently by starting a new thread for each
one. You cannot call them truly concurrently unless you have a separate
CPU for each function.

Mitchell Timin

--
"Many are stubborn in pursuit of the path they have chosen, few in
pursuit of the goal." - Friedrich Nietzsche

http://annevolve.sourceforge.net is what I'm into nowadays.
Humans may write to me at this address: zenguy at shaw dot ca
Jul 18 '05 #2
In article <c6**********@s olaris.cc.vt.ed u>,
bart_nessux <ba*********@ho tmail.com> wrote:
I need a script to call several functions at the same time. How does one
call more than one function simultaneously?


This has several smart-alecky answers, including "you don't",
and "with co-routines". The best way you can help yourself is
to describe a concrete situation where your (Python?) script
has a need to call even two functions simultaneously. It turns
out "simultaneously " has a plethora of meanings, and you're the
only one in a position to get others to understand which you
have in mind.

It'll also help to know whether you mean "function" as specific
to the Python language, or more abstractly, as a unit of useful
accomplishment.
--

Cameron Laird <cl****@phaseit .net>
Business: http://www.Phaseit.net
Jul 18 '05 #3
Cameron Laird wrote:
In article <c6**********@s olaris.cc.vt.ed u>,
bart_nessux <ba*********@ho tmail.com> wrote:
I need a script to call several functions at the same time. How does one
call more than one function simultaneously?

This has several smart-alecky answers, including "you don't",
and "with co-routines". The best way you can help yourself is
to describe a concrete situation where your (Python?) script
has a need to call even two functions simultaneously.


I need to ping 4 hosts at exactly the same time from the same machine (I
plan to timestamp the pings) to test and measure network conditions over
different routes to different hosts. Putting all the ping hosts in a list
and looping through it is not a fair or balanced way to do this because of
the time differences.
It turns
out "simultaneously " has a plethora of meanings, and you're the
only one in a position to get others to understand which you
have in mind.
I mean it to mean: at the *exact* same time... concurrently. Like runners
starting a race together.

It'll also help to know whether you mean "function" as specific
to the Python language, or more abstractly, as a unit of useful
accomplishment.


Specific to Python.
Jul 18 '05 #4

"Bart Nessux" <ba*********@ho tmail.com> wrote in message
news:c6******** **@solaris.cc.v t.edu...
I need to ping 4 hosts at exactly the same time from the same machine (I
plan to timestamp the pings) to test and measure network conditions over
different routes to different hosts. Putting all the ping hosts in a list
and looping through it is not a fair or balanced way to do this because of the time differences.


If you do 24 trials, one for each permutation, the result would be about as
fair and balanced as you can get.

Terry J. Reedy


Jul 18 '05 #5
bart_nessux wrote:
I need a script to call several functions at the same time. How does one
call more than one function simultaneously?

i just added my first thread to a wxpython program today. simple. in
fact my first threaded program of any kind.

as indicated, threads might help you. you didn't mention your platform
but probably it has real thread support. nevertheless, this might not
be for you if you are running in a Unix environment with a
multiprocessing (forking) program.

you launch your threads:

import thread

# create a lock you can use to block the threads until you are ready
mymutex = thread.allocate _lock()

def MyConcurrentFun ction():
# important concurrent stuff
pass

def ThreadThing():
# thread will hang on 'acquire' until mutex is released
mymutex.acquire ()
# release lock for the next thread
mymutex.release ()
# now do your stuff
MyConcurrentFun ction()

mymutex.acquire ()
# launch your threads
thread.start_ne w_thread(Thread Thing, ())
thread.start_ne w_thread(Thread Thing, ())
thread.start_ne w_thread(Thread Thing, ())...
# your threads are all hung on the 'acquire' statement
# release the lock, unblocking the threads
mymutex.release ()
# now all your threads are grabbing and releasing the mutex

# all done

I just made that whole thing up. But i think that's more or less how
you launch threads.

you have to consider that the thread may run as soon as you launch it.
each thread could complete your special function before the rest of the
threads get launched.

i think you address that problem by creating a mutex or semaphore that
each thread must acquire before it can proceed. That is, the thread
will block (hang) waiting for the mutex to become available. (think of
a mutex as an abstract lock resource). when all your threads are
launched, the main program can release the mutex(es), unblocking the
threads. The threads will unhang, and do your concurrent thing, more or
less concurrently.

Understand that concurrency is not guaranteed (as i understand it). the
OS controls which thread runs when, and it is not deterministic.

you could use an list of mutexes, to get an iota more concurrency.

all this i learned this very day from Programming Python, pg 104. so
take my advice with a shovel of salt.

but it sounds like the way to go to me.
Jul 18 '05 #6
In article <c6**********@s olaris.cc.vt.ed u>,
Bart Nessux <ba*********@ho tmail.com> wrote:
Jul 18 '05 #7
In article <c6**********@s olaris.cc.vt.ed u>, Bart Nessux wrote:
I need to ping 4 hosts at exactly the same time from the same machine
That simply can't be done.
(I plan to timestamp the pings) to test and measure network
conditions over different routes to different hosts. Putting
all the ping hosts in a list and looping through it is not a
fair or balanced way to do this because of the time
differences.
Exactly how many packets do you think are allowed on the wire
at once with Ethernet??
I mean it to mean: at the *exact* same time... concurrently. Like runners
starting a race together.


Not physically possible unless you've got 4 cpus with, 4
separate PCI buses, 4 Ethernet boards on 4 different Ethernet
segments, and some very special HW/SW to keep things
synchronized.

--
Grant Edwards grante Yow! I'm ANN LANDERS!! I
at can SHOPLIFT!!
visi.com
Jul 18 '05 #8
sigh. i just read what you want to do.

my answer was so cool too.

you are doing network diagnostics. it is unlikely that a non-network guy
(you) can cobble together a few lines of script and develop much in the
way of detailed diagnostics.

much better to find someone who already knows networking and use the
great many highly sophisticated tools that are already available (and free).

good luck

Jul 18 '05 #9
Bart Nessux wrote:
Cameron Laird wrote:

In article <c6**********@s olaris.cc.vt.ed u>,
bart_nessux <ba*********@ho tmail.com> wrote:
I need a script to call several functions at the same time. How does one
call more than one function simultaneously?


This has several smart-alecky answers, including "you don't",
and "with co-routines". The best way you can help yourself is
to describe a concrete situation where your (Python?) script
has a need to call even two functions simultaneously.

I need to ping 4 hosts at exactly the same time from the same machine (I
plan to timestamp the pings) to test and measure network conditions over
different routes to different hosts. Putting all the ping hosts in a list
and looping through it is not a fair or balanced way to do this because of
the time differences.

It turns
out "simultaneously " has a plethora of meanings, and you're the
only one in a position to get others to understand which you
have in mind.

I mean it to mean: at the *exact* same time... concurrently. Like runners
starting a race together.

It'll also help to know whether you mean "function" as specific
to the Python language, or more abstractly, as a unit of useful
accomplishmen t.

Specific to Python.

You can't get greater then 1ms accuracy when measuring a time on todays
machines, and that will be less when measuring time over a network...
calling 4 ping functions one after the other will complete in much less
then 1ms (assuming its asynchronous, or threaded). So, even if you could
manage to send 4 packets at *exactly* the same time, it would be no more
accurate.

not sure how your planning to ping the hosts... check out the asyncore
and threading modules.
Jul 18 '05 #10

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

Similar topics

12
2442
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone give me some advice? I don't know where to go to look this information up. Do I need to access the stack, and hence do some kind of inline...
2
1815
by: Joe | last post by:
I have 3 functions: ClientInfoA is doing something ClientInfoB is doing something SelectFunction2Run is a function to determine which function needed to run based on the value of the variable Method2Run. If the clientType is A, it would run ClientInfoA function. If it is clientType B, it would run the ClientInfoB function. Based on the...
19
4229
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
5
2208
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its nitty gritty but its necessary for my program. thanks dave
18
4323
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters,...
7
1896
by: Kenneth Brody | last post by:
The recent thread on "query about main()" got me thinking... As I recall, calling a function with the wrong parameters causes undefined behavior. (These all assume that no prototype of foo() is in scope.) For example: ==== fileA.c
11
3401
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the vtable pointer is made use of.. eg. class one {
4
4786
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread completes it invokes a method from the calling thread. Sort event driven concept with threads. Thanks. Ed Gomez
10
3240
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7946
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7791
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.