plpythonu and "hello concurrent world"

Discussion in 'Python' started by Gerardo Herzig, Dec 5, 2007.

  1. 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
     
    Gerardo Herzig, Dec 5, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nut Cracker
    Replies:
    1
    Views:
    341
  2. jakk
    Replies:
    4
    Views:
    12,221
  3. Tim Meagher
    Replies:
    8
    Views:
    1,292
    Karl Seguin
    Jun 18, 2005
  4. titi

    if and and vs if and,and

    titi, Mar 9, 2007, in forum: VHDL
    Replies:
    4
    Views:
    591
    Mike Treseler
    Mar 11, 2007
  5. Martin Marcher

    plpythonu+postgrs anybody using it?

    Martin Marcher, Apr 2, 2008, in forum: Python
    Replies:
    1
    Views:
    275
    Matthew Woodcraft
    Apr 2, 2008
Loading...

Share This Page