From: Gerardo Herzig <gherzig@fmed.uba.ar>
To: python-list@python.org
To: pgsql-sql@postgresql.org
Subject: plpythonu and "hello concurrent world"
Date: Wed, 05 Dec 2007 10:10:02 -0300
Message-ID: <4756A32A.9020101@fmed.uba.ar> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: gherzig@fmed.uba.ar, python-list@python.org
Subject: Re: plpythonu and "hello concurrent world"
In-Reply-To: <4756A32A.9020101@fmed.uba.ar>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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