pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedplpythonu and "hello concurrent world"
3+ messages / 2 participants
[nested] [flat]
* plpythonu and "hello concurrent world"
@ 2007-12-05 13:10 Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 1 reply; 3+ messages in thread
From: Gerardo Herzig @ 2007-12-05 13:10 UTC (permalink / raw)
To: python-list@python.org; pgsql-sql
Hi all. Im having some "problems" with a small concurrent plpython function.
Based on a small example [1] about concurrent programming, there is some
code which works fine under python:
#! /usr/bin/python
import threading, random
import time
def myPrint(str):
print 'searching...', str
time.sleep(random.randint(10, 10000) / 1000.0)
print str, 'OK!'
myThreads = (threading.Timer(random.random(), myPrint, ["hello"]), \
threading.Timer(random.random(), myPrint, ["concurrent"]), \
threading.Timer(random.random(), myPrint, ["world"]))
for thr in myThreads:
thr.start()
gherzig@linux: python pp.py
searching... concurrent
searching... world
searching... hello
hello OK!
concurrent OK!
world OK!
So far, so good. Almost the same example in plpythonu:
CREATE OR REPLACE FUNCTION search_t()
returns bigint
security definer
as
$$
import threading, random
import time
def myPrint(str):
plpy.notice ('searching...', str)
time.sleep(random.randint(10, 10000) / 1000.0)
plpy.notice(str, 'OK!')
myThreads = (threading.Timer(random.random(), myPrint, ["hello"]), \
threading.Timer(random.random(), myPrint, ["concurrent"]), \
threading.Timer(random.random(), myPrint, ["world"]))
for thr in myThreads:
thr.start()
return 10000
$$ language plpythonu;
gse_new_version=# select * From search_t();
search_t
----------
10000
(1 row)
Looks like myPrint() is not executing at all!!
Have no idea why, so i decided writing both on python and postgres
forums. Any ideas??
Postgres 8.1.3
python 2.5.1
Thanks!!
Gerardo
[1]
http://forums.hostrocket.com/showthread.php?t=13325
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: plpythonu and "hello concurrent world"
@ 2007-12-05 14:42 Tom Lane <tgl@sss.pgh.pa.us>
parent: Gerardo Herzig <gherzig@fmed.uba.ar>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2007-12-05 14:42 UTC (permalink / raw)
To: Gerardo Herzig <gherzig@fmed.uba.ar>; +Cc: python-list@python.org; pgsql-sql
Gerardo Herzig <gherzig@fmed.uba.ar> writes:
> Hi all. Im having some "problems" with a small concurrent plpython function.
Don't even *think* about starting multiple threads inside the Postgres
backend. It's an excellent way to break things.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: plpythonu and "hello concurrent world"
@ 2007-12-05 15:19 Gerardo Herzig <gherzig@fmed.uba.ar>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Gerardo Herzig @ 2007-12-05 15:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
Tom Lane wrote:
>Gerardo Herzig <gherzig@fmed.uba.ar> writes:
>
>
>>Hi all. Im having some "problems" with a small concurrent plpython function.
>>
>>
>
>Don't even *think* about starting multiple threads inside the Postgres
>backend. It's an excellent way to break things.
>
> regards, tom lane
>
>---------------------------(end of broadcast)---------------------------
>TIP 6: explain analyze is your friend
>
>
>
>
Damn!! Well, comming from you Tom, i guess i will just look for another
approach without complaining ^^.
Thanks!
Gerardo
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-12-05 15:19 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-12-05 13:10 plpythonu and "hello concurrent world" Gerardo Herzig <gherzig@fmed.uba.ar>
2007-12-05 14:42 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-12-05 15:19 ` Gerardo Herzig <gherzig@fmed.uba.ar>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox