Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:49:49+00:00 2026-06-11T12:49:49+00:00

I am making a small program to evaluate and plot the linear canonical transform

  • 0

I am making a small program to evaluate and plot the linear canonical transform of a function:

from scipy import *
from scipy.integrate import *
import time
from threading import *
def lct(f, a, b, c, d):
    def X(u):
        coeff=sqrt(-1j)*e**(1j*pi*(d/b)*(u**2))
        integrand_R= lambda t,f,a,b: (e**(-2j*pi*u*t/b)*e**(1j*pi*a*t**2/b)*f(t)).real
        integrand_I= lambda t,f,a,b: (e**(-2j*pi*u*t/b)*e**(1j*pi*a*t**2/b)*f(t)).imag
        # integral= sum of integrals of real and imaginary parts
        integral=quad(integrand_R,-Inf,0,args=(f,a,b))[0]+1j*quad(integrand_I,-Inf,0,args=(f,a,b))[0]
        #print(integral)
        return coeff*integral
    return X
class Executor(Thread):
    def __init__(self, f):
        self._f = f
        Thread.__init__(self)
    def run(self):
        y=[self._f(x_i) for x_i in x]
    def result():
        return y
#thread pool
class Pool:
    def map(self,f,x):
        executors=[Executor(f) for i in range(1)]
        x=x.reshape(8,-1)
        for i in range(len(executors)):
            executors[i].x=x[i]
            executors[i].start()
            #executors[i].join()
        #raise TypeError
        for e in executors:
            e.join()
        raise TypeError#execution does not make it this far if two threads are used




start=time.clock()

p=Pool()
x=arange(4,step=0.005)
test_lct=lct(lambda x: sin(x),1,2,3,7)
def test():
    y=abs(p.map(test_lct,x))
    raise TypeError
    figure(figsize=(6*3.13,4*3.13/2))
    plot(x,y)
    for i in range(y.size):
        if y[i]>1e15:
            print(x[i])
            print(y[i])
            print('\n')
            print(x[130:140])
            print('\n')
            print(y[130:140])
            print('\n')
test()
test_lct=lct(lambda x: sin(2*x),1,2,3,7)
test()

stop=time.clock()
print(stop-start)

The work is supposed to be divided among 8 threads by the thread pool the but if I change executors=[Executor(f) for i in range(1)](line 26) to executors=[Executor(f) for i in range(2)], Python crashes: “python.exe has stopped working”. Why do two threads crash python?

Note: this can be run without the interactive interpreter / matplotlib because it stops before plot() is called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:49:51+00:00Added an answer on June 11, 2026 at 12:49 pm

    Try using multiprocessing.Pool. It avoids the GIL by using multiple processes.

    I don’t have scipy installed, so I can’t test it, but try something like this.

    from scipy import *
    from scipy.integrate import *
    import time
    from multiprocessing import Pool
    from matplotlib.pyplot import figure, plot
    
    def lct(f, a, b, c, d):
        def X(u):
            coeff=sqrt(-1j)*e**(1j*pi*(d/b)*(u**2))
            integrand_R= lambda t,f,a,b: (e**(-2j*pi*u*t/b)*e**(1j*pi*a*t**2/b)*f(t)).real 
            integrand_I= lambda t,f,a,b: (e**(-2j*pi*u*t/b)*e**(1j*pi*a*t**2/b)*f(t)).imag 
            # integral= sum of integrals of real and imaginary parts
            integral=quad(integrand_R,-Inf,0,args=(f,a,b))[0]+1j*quad(integrand_I,-Inf,0,args=(f,a,b))[0]
            #print(integral)
            return coeff*integral
        return X
    
    def test():
        global test_lct, x
        y=abs(p.map(test_lct,x))
        figure(figsize=(6*3.13,4*3.13/2))
        plot(x,y)
        for i in range(y.size):
            if y[i]>1e15:
                print(x[i])
                print(y[i])
                print('\n')
                print(x[130:140])
                print('\n')
                print(y[130:140])
                print('\n')
    
    if __name__ == '__main__':
      p=Pool()
      x=arange(4,step=0.005)
      start=time.clock()
      test_lct=lct(lambda x: sin(x),1,2,3,7)
      test()
      test_lct=lct(lambda x: sin(2*x),1,2,3,7)
      test()
      stop=time.clock()
      print(stop-start)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a small program to draw segments in python using wxpython and
I'm currently making a small program to teach me some new Java, and I'm
I'm making a small program for math (no particular reason, just kind of wanted
How would I go about making a small program that keeps moving the mouse
I'm making a small Python program, which calls the webbrowser module to open a
Making a small WCF test program which is based on a Store that has
I wrote a small program to evaluate the state of cellular automata and paint
I am making a small program that reads a text file and stores it
I'm making a small program to place orders on our supplier's web site. I
I'm currently learning Windows/DOS assembly. I'm just making a small program that adds two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.