Multithreading in PythonScript

Forum Forums Visual Components 4.1 Python Programming in VC Multithreading in PythonScript

This topic contains 3 replies, has 3 voices, and was last updated by Avatar BaiYang 3 weeks, 1 day ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17149
    Avatar
    BaiYang
    Participant

    Hello,

    i have wrote a multithreading program in PythonScript using “thread” module,but it shows a error dialog as follow:

    the code as follow:

    from vcScript import *
    import thread

    def f1():
    while True:
    delay(1)
    print(‘————-thread1—————‘)
    print(‘thread1’)
    def f2():
    while True:
    delay(1)
    print(‘————-thread2—————‘)
    print(‘thread2’)

    def OnRun():
    thread.start_new_thread(f1,(‘thread1’,1))
    thread.start_new_thread(f2,(‘thread2’,2))
    delay(100)

    Does anyone know how to solve this problem?

    Thanks for your help.

    #17158
    Avatar
    CaptainFeature
    Participant

    Hy,

    i think Multithreading is not supported in Python-Scripts of components…

    Why do you need it?

    Regards

    #17153
    Avatar
    deadeye
    Participant

    I guess you’re using the module thread, which should not exposed to the user.
    In normal CPython 2.7 it is a very low level implementation and should not be used (Python 2.7 aswell).

    Here is an example from Stackless Python 2.7. This implementation of Python is used in VC. The usage differs a little bit. You can have “channels” which are a kind of message queue and schedulers.

    https://stackless.readthedocs.io/en/2.7-slp/library/stackless/threads.html

    Try as first if the provided examples are working.

    #17232
    Avatar
    BaiYang
    Participant

    @ Captain_Feature

    I want to execute two parallel tasks in one python script,because the two tasks share the same resource .

    @deadeye

    Thanks for your reply,i will have a try.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.